Rename VersionSet to Constraints
VersionSet is a wrapper around version.Contraints, so rename it it as such.
This commit is contained in:
parent
718ede0636
commit
7d2d951f27
|
@ -94,7 +94,7 @@ func providersCommandPopulateTreeNode(node treeprint.Tree, deps *moduledeps.Modu
|
|||
|
||||
for _, name := range names {
|
||||
dep := deps.Providers[moduledeps.ProviderInstance(name)]
|
||||
versionsStr := dep.Versions.String()
|
||||
versionsStr := dep.Constraints.String()
|
||||
if versionsStr != "" {
|
||||
versionsStr = " " + versionsStr
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ type Providers map[ProviderInstance]ProviderDependency
|
|||
// instance, including both the set of allowed versions and the reason for
|
||||
// the dependency.
|
||||
type ProviderDependency struct {
|
||||
Versions discovery.VersionSet
|
||||
Reason ProviderDependencyReason
|
||||
Constraints discovery.Constraints
|
||||
Reason ProviderDependencyReason
|
||||
}
|
||||
|
||||
// ProviderDependencyReason is an enumeration of reasons why a dependency might be
|
||||
|
|
|
@ -114,9 +114,9 @@ func (m *Module) PluginRequirements() discovery.PluginRequirements {
|
|||
// by using Intersection to merge the version sets.
|
||||
pty := inst.Type()
|
||||
if existing, exists := ret[pty]; exists {
|
||||
ret[pty] = existing.Intersection(dep.Versions)
|
||||
ret[pty] = existing.Intersection(dep.Constraints)
|
||||
} else {
|
||||
ret[pty] = dep.Versions
|
||||
ret[pty] = dep.Constraints
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
@ -163,7 +163,7 @@ func (m *Module) Equal(other *Module) bool {
|
|||
}
|
||||
|
||||
// Can't use reflect.DeepEqual on this provider structure because
|
||||
// the nested VersionSet objects contain function pointers that
|
||||
// the nested Constraints objects contain function pointers that
|
||||
// never compare as equal. So we'll need to walk it the long way.
|
||||
for inst, dep := range m.Providers {
|
||||
if _, exists := other.Providers[inst]; !exists {
|
||||
|
@ -174,10 +174,10 @@ func (m *Module) Equal(other *Module) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// VersionSets are not too easy to compare robustly, so
|
||||
// Constraints are not too easy to compare robustly, so
|
||||
// we'll just use their string representations as a proxy
|
||||
// for now.
|
||||
if dep.Versions.String() != other.Providers[inst].Versions.String() {
|
||||
if dep.Constraints.String() != other.Providers[inst].Constraints.String() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,13 +192,13 @@ func TestModulePluginRequirements(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: Providers{
|
||||
"foo": ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
},
|
||||
"foo.bar": ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
},
|
||||
"baz": ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=3.0.0").MustParse(),
|
||||
Constraints: discovery.ConstraintStr(">=3.0.0").MustParse(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ package discovery
|
|||
// kind) that are required to exist and have versions within the given
|
||||
// corresponding sets.
|
||||
//
|
||||
// PluginRequirements is a map from plugin name to VersionSet.
|
||||
type PluginRequirements map[string]VersionSet
|
||||
// PluginRequirements is a map from plugin name to Constraints.
|
||||
type PluginRequirements map[string]Constraints
|
||||
|
||||
// Merge takes the contents of the receiver and the other given requirements
|
||||
// object and merges them together into a single requirements structure
|
||||
|
|
|
@ -9,18 +9,18 @@ import (
|
|||
// obtain a real Constraint object, or discover that it is invalid.
|
||||
type ConstraintStr string
|
||||
|
||||
// Parse transforms a ConstraintStr into a VersionSet if it is
|
||||
// Parse transforms a ConstraintStr into a Constraints if it is
|
||||
// syntactically valid. If it isn't then an error is returned instead.
|
||||
func (s ConstraintStr) Parse() (VersionSet, error) {
|
||||
func (s ConstraintStr) Parse() (Constraints, error) {
|
||||
raw, err := version.NewConstraint(string(s))
|
||||
if err != nil {
|
||||
return VersionSet{}, err
|
||||
return Constraints{}, err
|
||||
}
|
||||
return VersionSet{raw}, nil
|
||||
return Constraints{raw}, nil
|
||||
}
|
||||
|
||||
// MustParse is like Parse but it panics if the constraint string is invalid.
|
||||
func (s ConstraintStr) MustParse() VersionSet {
|
||||
func (s ConstraintStr) MustParse() Constraints {
|
||||
ret, err := s.Parse()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -28,33 +28,30 @@ func (s ConstraintStr) MustParse() VersionSet {
|
|||
return ret
|
||||
}
|
||||
|
||||
// VersionSet represents a set of versions which any given Version is either
|
||||
// Constraints represents a set of versions which any given Version is either
|
||||
// a member of or not.
|
||||
type VersionSet struct {
|
||||
// Internally a version set is actually a list of constraints that
|
||||
// *remove* versions from the set. Thus a VersionSet with an empty
|
||||
// Constraints list would be one that contains *all* versions.
|
||||
type Constraints struct {
|
||||
raw version.Constraints
|
||||
}
|
||||
|
||||
// AllVersions is a VersionSet containing all versions
|
||||
var AllVersions VersionSet
|
||||
// AllVersions is a Constraints containing all versions
|
||||
var AllVersions Constraints
|
||||
|
||||
func init() {
|
||||
AllVersions = VersionSet{
|
||||
AllVersions = Constraints{
|
||||
raw: make(version.Constraints, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if the given version is in the receiving set.
|
||||
func (s VersionSet) Has(v Version) bool {
|
||||
func (s Constraints) Has(v Version) bool {
|
||||
return s.raw.Check(v.raw)
|
||||
}
|
||||
|
||||
// Intersection combines the receving set with the given other set to produce a
|
||||
// set that is the intersection of both sets, which is to say that it contains
|
||||
// only the versions that are members of both sets.
|
||||
func (s VersionSet) Intersection(other VersionSet) VersionSet {
|
||||
// Intersection combines the receiving set with the given other set to produce
|
||||
// a set that is the intersection of both sets, which is to say that resulting
|
||||
// constraints contain only the versions that are members of both.
|
||||
func (s Constraints) Intersection(other Constraints) Constraints {
|
||||
raw := make(version.Constraints, 0, len(s.raw)+len(other.raw))
|
||||
|
||||
// Since "raw" is a list of constraints that remove versions from the set,
|
||||
|
@ -63,11 +60,11 @@ func (s VersionSet) Intersection(other VersionSet) VersionSet {
|
|||
raw = append(raw, s.raw...)
|
||||
raw = append(raw, other.raw...)
|
||||
|
||||
return VersionSet{raw}
|
||||
return Constraints{raw}
|
||||
}
|
||||
|
||||
// String returns a string representation of the set members as a set
|
||||
// of range constraints.
|
||||
func (s VersionSet) String() string {
|
||||
func (s Constraints) String() string {
|
||||
return s.raw.String()
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ func moduleTreeConfigDependencies(root *module.Tree, inheritProviders map[string
|
|||
versionSet = discovery.ConstraintStr(pCfg.Version).MustParse()
|
||||
}
|
||||
providers[inst] = moduledeps.ProviderDependency{
|
||||
Versions: versionSet,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: versionSet,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,8 +84,8 @@ func moduleTreeConfigDependencies(root *module.Tree, inheritProviders map[string
|
|||
}
|
||||
|
||||
providers[inst] = moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: reason,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: reason,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,8 +146,8 @@ func moduleTreeMergeStateDependencies(root *moduledeps.Module, state *State) {
|
|||
module.Providers = make(moduledeps.Providers)
|
||||
}
|
||||
module.Providers[inst] = moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
"foo.bar": moduledeps.ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
|
@ -58,8 +58,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
|
@ -72,12 +72,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
},
|
||||
"foo.baz": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
|
@ -90,8 +90,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
|
@ -104,12 +104,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
"bar": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
|
@ -117,12 +117,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "child",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
},
|
||||
"baz": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
|
@ -130,12 +130,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "grandchild",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
"bar": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -163,8 +163,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
|
@ -209,16 +209,16 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
"foo": moduledeps.ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
"foo.bar": moduledeps.ProviderDependency{
|
||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
"baz": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
|
@ -229,8 +229,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
|||
Name: "grandchild",
|
||||
Providers: moduledeps.Providers{
|
||||
"banana": moduledeps.ProviderDependency{
|
||||
Versions: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
--- FAIL: TestContext2Plan_moduleProviderInherit (0.01s)
|
||||
context_plan_test.go:552: bad: []string{"child"}
|
||||
map[string]dag.Vertex{}
|
||||
"module.middle.null"
|
||||
map[string]dag.Vertex{}
|
||||
"module.middle.module.inner.null"
|
||||
map[string]dag.Vertex{}
|
||||
"aws"
|
||||
FAIL
|
Loading…
Reference in New Issue