From 831d84c940f4aec365973bd4e35eb891bdf1b732 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Mon, 28 Aug 2017 12:20:21 +0200 Subject: [PATCH] build: make tests independent of build tags When the metadata server is scanning the agents for potential servers it is parsing the version number which the agent provided when it joined. This version number has to conform to a certain format, i.e. 'n.n.n'. Without this version number properly set some tests fail with error messages that disguise the root cause. The default version number is currently set to 'unknown' in version/version.go which does not parse and triggers the tests to fail. The work around is to use a build tag 'consul' which will use the version number set in version_base.go instead which has the correct format and is set to the current release version. In addition, some parts of the code also require the version number to be of a certain value. Setting it to '0.0.0' for example makes some tests pass and others fail since they don't pass the semantic check. When using go build/install/test one has to remember to use '-tags consul' or tests will fail with non-obvious error messages. Using build tags makes the build process more complex and error prone since it prevents the use of the plain go toolchain and - at least in its current form - introduces subtle build and test issues. We should try to eliminate build tags for anything else but platform specific code. This patch removes all references to specific version numbers in the code and tests and sets the default version to '9.9.9' which is syntactically correct and passes the semantic check. This solves the issue of running go build/install/test without tags for the OSS build. --- agent/acl_endpoint_test.go | 1 - agent/agent_test.go | 5 ----- agent/consul/config.go | 3 ++- command/util_test.go | 5 ----- version/version.go | 7 ++++++- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/agent/acl_endpoint_test.go b/agent/acl_endpoint_test.go index 059bb8cbd8..6a5874166f 100644 --- a/agent/acl_endpoint_test.go +++ b/agent/acl_endpoint_test.go @@ -34,7 +34,6 @@ func makeTestACL(t *testing.T, srv *HTTPServer) string { func TestACL_Bootstrap(t *testing.T) { t.Parallel() cfg := TestACLConfig() - cfg.Version = "0.9.1" cfg.ACLMasterToken = "" a := NewTestAgent(t.Name(), cfg) defer a.Shutdown() diff --git a/agent/agent_test.go b/agent/agent_test.go index 3ffbacc22f..348b3b48cc 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -19,16 +19,11 @@ import ( "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/testutil" "github.com/hashicorp/consul/types" - "github.com/hashicorp/consul/version" "github.com/hashicorp/go-uuid" "github.com/hashicorp/raft" "github.com/pascaldekloe/goe/verify" ) -func init() { - version.Version = "0.8.0" -} - func externalIP() (string, error) { addrs, err := net.InterfaceAddrs() if err != nil { diff --git a/agent/consul/config.go b/agent/consul/config.go index 771f72df59..2361161cf3 100644 --- a/agent/consul/config.go +++ b/agent/consul/config.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/tlsutil" "github.com/hashicorp/consul/types" + "github.com/hashicorp/consul/version" "github.com/hashicorp/memberlist" "github.com/hashicorp/raft" "github.com/hashicorp/serf/serf" @@ -344,7 +345,7 @@ func DefaultConfig() *Config { } conf := &Config{ - Build: "0.8.0", + Build: version.Version, Datacenter: DefaultDC, NodeName: hostname, RPCAddr: DefaultRPCAddr, diff --git a/command/util_test.go b/command/util_test.go index 8f73984ba2..11961a0024 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -4,14 +4,9 @@ import ( "strings" "testing" - "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" ) -func init() { - version.Version = "0.8.0" -} - func assertNoTabs(t *testing.T, c cli.Command) { if strings.ContainsRune(c.Help(), '\t') { t.Errorf("%#v help output contains tabs", c) diff --git a/version/version.go b/version/version.go index 1acae6706c..2410d40594 100644 --- a/version/version.go +++ b/version/version.go @@ -13,7 +13,12 @@ var ( // Release versions of the build. These will be filled in by one of the // build tag-specific files. - Version = "unknown" + // + // Version must conform to the format expected by github.com/hashicorp/go-version + // for tests to work. Otherwise, the metadata server will not be able to detect + // the agent to be a server. The value must be >= '0.8.0' for autopilot to work. + // todo(fs): This still feels like a hack but at least the magic values are gone. + Version = "9.9.9" VersionPrerelease = "unknown" )