rename some Constraints methods per code review

This commit is contained in:
James Bardin 2017-05-04 18:53:02 -04:00 committed by Martin Atkins
parent 211f5b5d6e
commit 044ad5ef59
7 changed files with 10 additions and 10 deletions

View File

@ -39,7 +39,7 @@ func (m mockGetProvider) GetProvider(dst, provider string, req discovery.Constra
panic(err) panic(err)
} }
if req.Has(version) { if req.Allows(version) {
// provider filename // provider filename
name := m.FileName(provider, v) name := m.FileName(provider, v)
path := filepath.Join(dst, name) path := filepath.Join(dst, name)

View File

@ -114,7 +114,7 @@ func (m *Module) PluginRequirements() discovery.PluginRequirements {
// by using Intersection to merge the version sets. // by using Intersection to merge the version sets.
pty := inst.Type() pty := inst.Type()
if existing, exists := ret[pty]; exists { if existing, exists := ret[pty]; exists {
ret[pty] = existing.Intersection(dep.Constraints) ret[pty] = existing.Append(dep.Constraints)
} else { } else {
ret[pty] = dep.Constraints ret[pty] = dep.Constraints
} }

View File

@ -90,7 +90,7 @@ func newestVersion(available []Version, required Constraints) (Version, error) {
found := false found := false
for _, v := range available { for _, v := range available {
if required.Has(v) { if required.Allows(v) {
if !found { if !found {
latest = v latest = v
found = true found = true

View File

@ -139,7 +139,7 @@ func (s PluginMetaSet) ConstrainVersions(reqd PluginRequirements) map[string]Plu
if err != nil { if err != nil {
panic(err) panic(err)
} }
if allowedVersions.Has(version) { if allowedVersions.Allows(version) {
ret[p.Name].Add(p) ret[p.Name].Add(p)
} }
} }

View File

@ -17,7 +17,7 @@ func (r PluginRequirements) Merge(other PluginRequirements) PluginRequirements {
} }
for n, vs := range other { for n, vs := range other {
if existing, exists := ret[n]; exists { if existing, exists := ret[n]; exists {
ret[n] = existing.Intersection(vs) ret[n] = existing.Append(vs)
} else { } else {
ret[n] = vs ret[n] = vs
} }

View File

@ -43,15 +43,15 @@ func init() {
} }
} }
// Has returns true if the given version is in the receiving set. // Allows returns true if the given version is in the receiving set.
func (s Constraints) Has(v Version) bool { func (s Constraints) Allows(v Version) bool {
return s.raw.Check(v.raw) return s.raw.Check(v.raw)
} }
// Intersection combines the receiving set with the given other set to produce // Append 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 // 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. // constraints contain only the versions that are members of both.
func (s Constraints) Intersection(other Constraints) Constraints { func (s Constraints) Append(other Constraints) Constraints {
raw := make(version.Constraints, 0, len(s.raw)+len(other.raw)) raw := make(version.Constraints, 0, len(s.raw)+len(other.raw))
// Since "raw" is a list of constraints that remove versions from the set, // Since "raw" is a list of constraints that remove versions from the set,

View File

@ -56,7 +56,7 @@ func TestVersionSet(t *testing.T) {
t.Fatalf("unwanted error parsing version string %q: %s", test.VersionStr, err) t.Fatalf("unwanted error parsing version string %q: %s", test.VersionStr, err)
} }
if got, want := accepted.Has(version), test.ShouldHave; got != want { if got, want := accepted.Allows(version), test.ShouldHave; got != want {
t.Errorf("Has returned %#v; want %#v", got, want) t.Errorf("Has returned %#v; want %#v", got, want)
} }
}) })