From 9247dc9108a6984ae34acd9bd9dc1b9a58821e4a Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Fri, 20 Sep 2024 14:46:01 -0400 Subject: [PATCH] E2E: allow Consul version to omit tags (#24024) When we start the Consul agent in the `consulcompat` test package, we check that the version matches the version we expect. But Consul agents may omit non-core parts of the version string (ex. `1.20.0-rc1` displays `1.20.0`). Compare only the core portions of the version string. --- e2e/consulcompat/shared_run_test.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/e2e/consulcompat/shared_run_test.go b/e2e/consulcompat/shared_run_test.go index 33fd4f3bb..239edcbf1 100644 --- a/e2e/consulcompat/shared_run_test.go +++ b/e2e/consulcompat/shared_run_test.go @@ -13,6 +13,7 @@ import ( "time" consulapi "github.com/hashicorp/consul/api" + "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/api" nomadapi "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/helper/uuid" @@ -23,25 +24,37 @@ import ( // verifyConsulVersion ensures that we've successfully spun up a Consul cluster // on the expected version (this ensures we don't have stray running Consul from // previous runs or from the development environment) -func verifyConsulVersion(t *testing.T, consulAPI *consulapi.Client, version string) { +func verifyConsulVersion(t *testing.T, consulAPI *consulapi.Client, expectVersion string) { self, err := consulAPI.Agent().Self() must.NoError(t, err) vers := self["Config"]["Version"].(string) - must.Eq(t, version, vers) + + check, err := version.NewSemver(vers) + must.NoError(t, err) + + expect, _ := version.NewSemver(expectVersion) + must.Eq(t, expect.Core(), check.Core()) } // verifyConsulFingerprint ensures that we've successfully fingerprinted Consul -func verifyConsulFingerprint(t *testing.T, nc *nomadapi.Client, version, clusterName string) { +func verifyConsulFingerprint(t *testing.T, nc *nomadapi.Client, expectVersion, clusterName string) { stubs, _, err := nc.Nodes().List(nil) must.NoError(t, err) must.Len(t, 1, stubs) node, _, err := nc.Nodes().Info(stubs[0].ID, nil) + var vers string if clusterName == "default" { - must.Eq(t, version, node.Attributes["consul.version"]) + vers = node.Attributes["consul.version"] } else { - must.Eq(t, version, node.Attributes["consul."+clusterName+".version"]) + vers = node.Attributes["consul."+clusterName+".version"] } + + check, err := version.NewSemver(vers) + must.NoError(t, err) + + expect, _ := version.NewSemver(expectVersion) + must.Eq(t, expect.Core(), check.Core()) } // setupConsulACLsForServices installs a base set of ACL policies and returns a