From a357f5f197dbe54314608d4c5acbdd9e1959afba Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Mon, 1 Nov 2021 17:56:50 -0400 Subject: [PATCH] 18313: add a test for the grep/awk command used in the arvbox code. Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- lib/install/deps.go | 2 +- lib/install/deps_go_version_test.go | 40 +++++++++++++++++++++++++++++ tools/arvbox/bin/arvbox | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 lib/install/deps_go_version_test.go diff --git a/lib/install/deps.go b/lib/install/deps.go index ff00ee1e35..714604c845 100644 --- a/lib/install/deps.go +++ b/lib/install/deps.go @@ -29,6 +29,7 @@ import ( var Command cmd.Handler = &installCommand{} const devtestDatabasePassword = "insecure_arvados_test" +const goversion = "1.17.1" type installCommand struct { ClusterType string @@ -245,7 +246,6 @@ make install } if !prod { - goversion := "1.17.1" if havegoversion, err := exec.Command("/usr/local/bin/go", "version").CombinedOutput(); err == nil && bytes.HasPrefix(havegoversion, []byte("go version go"+goversion+" ")) { logger.Print("go " + goversion + " already installed") } else { diff --git a/lib/install/deps_go_version_test.go b/lib/install/deps_go_version_test.go new file mode 100644 index 0000000000..1a69b6e617 --- /dev/null +++ b/lib/install/deps_go_version_test.go @@ -0,0 +1,40 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +package install + +import ( + "bytes" + "os/exec" + "testing" + + "gopkg.in/check.v1" +) + +func Test(t *testing.T) { + check.TestingT(t) +} + +var _ = check.Suite(&Suite{}) + +type Suite struct{} + +/* + TestExtractGoVersion tests the grep/awk command used in + tools/arvbox/bin/arvbox to extract the version of Go to install for + bootstrapping `arvados-server`. + + If this test is changed, the arvbox code will also need to be updated. +*/ +func (*Suite) TestExtractGoVersion(c *check.C) { + script := ` + sourcepath="$(realpath ../..)" + (cd ${sourcepath} && grep 'const goversion =' lib/install/deps.go |awk -F'"' '{print $2}') + ` + cmd := exec.Command("bash", "-") + cmd.Stdin = bytes.NewBufferString("set -ex -o pipefail\n" + script) + cmdOutput, err := cmd.Output() + c.Assert(err, check.IsNil) + c.Assert(string(cmdOutput), check.Equals, goversion+"\n") +} diff --git a/tools/arvbox/bin/arvbox b/tools/arvbox/bin/arvbox index 785a7708b4..ca98ff63f1 100755 --- a/tools/arvbox/bin/arvbox +++ b/tools/arvbox/bin/arvbox @@ -401,7 +401,7 @@ build() { set -e # Get the go version we should use for bootstrapping - GO_VERSION=`grep 'goversion :=' $LOCAL_ARVADOS_ROOT/lib/install/deps.go |awk -F'"' '{print $2}'` + GO_VERSION=`grep 'const goversion =' $LOCAL_ARVADOS_ROOT/lib/install/deps.go |awk -F'"' '{print $2}'` if test "$1" = localdemo -o "$1" = publicdemo ; then BUILDTYPE=demo -- 2.30.2