From 044ad5ef595932949dcfa1cf9f330949f258dd50 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 4 May 2017 18:53:02 -0400 Subject: [PATCH] rename some Constraints methods per code review --- command/plugins_test.go | 2 +- moduledeps/module.go | 2 +- plugin/discovery/get.go | 2 +- plugin/discovery/meta_set.go | 2 +- plugin/discovery/requirements.go | 2 +- plugin/discovery/version_set.go | 8 ++++---- plugin/discovery/version_set_test.go | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/command/plugins_test.go b/command/plugins_test.go index 6c065b450..74544a3b1 100644 --- a/command/plugins_test.go +++ b/command/plugins_test.go @@ -39,7 +39,7 @@ func (m mockGetProvider) GetProvider(dst, provider string, req discovery.Constra panic(err) } - if req.Has(version) { + if req.Allows(version) { // provider filename name := m.FileName(provider, v) path := filepath.Join(dst, name) diff --git a/moduledeps/module.go b/moduledeps/module.go index d09c19738..0e446108f 100644 --- a/moduledeps/module.go +++ b/moduledeps/module.go @@ -114,7 +114,7 @@ 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.Constraints) + ret[pty] = existing.Append(dep.Constraints) } else { ret[pty] = dep.Constraints } diff --git a/plugin/discovery/get.go b/plugin/discovery/get.go index c53dd0ff5..bb8afae27 100644 --- a/plugin/discovery/get.go +++ b/plugin/discovery/get.go @@ -90,7 +90,7 @@ func newestVersion(available []Version, required Constraints) (Version, error) { found := false for _, v := range available { - if required.Has(v) { + if required.Allows(v) { if !found { latest = v found = true diff --git a/plugin/discovery/meta_set.go b/plugin/discovery/meta_set.go index 9fc0abb09..c5102d98f 100644 --- a/plugin/discovery/meta_set.go +++ b/plugin/discovery/meta_set.go @@ -139,7 +139,7 @@ func (s PluginMetaSet) ConstrainVersions(reqd PluginRequirements) map[string]Plu if err != nil { panic(err) } - if allowedVersions.Has(version) { + if allowedVersions.Allows(version) { ret[p.Name].Add(p) } } diff --git a/plugin/discovery/requirements.go b/plugin/discovery/requirements.go index 4f0857aa6..1f58821e4 100644 --- a/plugin/discovery/requirements.go +++ b/plugin/discovery/requirements.go @@ -17,7 +17,7 @@ func (r PluginRequirements) Merge(other PluginRequirements) PluginRequirements { } for n, vs := range other { if existing, exists := ret[n]; exists { - ret[n] = existing.Intersection(vs) + ret[n] = existing.Append(vs) } else { ret[n] = vs } diff --git a/plugin/discovery/version_set.go b/plugin/discovery/version_set.go index 73eae7591..e1b0b1e2c 100644 --- a/plugin/discovery/version_set.go +++ b/plugin/discovery/version_set.go @@ -43,15 +43,15 @@ func init() { } } -// Has returns true if the given version is in the receiving set. -func (s Constraints) Has(v Version) bool { +// Allows returns true if the given version is in the receiving set. +func (s Constraints) Allows(v Version) bool { 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 // 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)) // Since "raw" is a list of constraints that remove versions from the set, diff --git a/plugin/discovery/version_set_test.go b/plugin/discovery/version_set_test.go index ecd3b12d0..ed2c4f1b7 100644 --- a/plugin/discovery/version_set_test.go +++ b/plugin/discovery/version_set_test.go @@ -56,7 +56,7 @@ func TestVersionSet(t *testing.T) { 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) } })