18313: add a test for the grep/awk command used in the arvbox code.
authorWard Vandewege <ward@curii.com>
Mon, 1 Nov 2021 21:56:50 +0000 (17:56 -0400)
committerWard Vandewege <ward@curii.com>
Mon, 1 Nov 2021 21:58:42 +0000 (17:58 -0400)
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/install/deps.go
lib/install/deps_go_version_test.go [new file with mode: 0644]
tools/arvbox/bin/arvbox

index ff00ee1e350159ea82e2bc5a54293853708a8eef..714604c8454ed0ecbecbc59db6ba02c956da6104 100644 (file)
@@ -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 (file)
index 0000000..1a69b6e
--- /dev/null
@@ -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")
+}
index 785a7708b4b80e672972f22a3da75072fa40d3f9..ca98ff63f1492a55e7b4d03ad3442f3fd37b8665 100755 (executable)
@@ -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