From 56a8276a4a999dee18bb48df02dc4844defb3f0c Mon Sep 17 00:00:00 2001 From: Dane Strandboge Date: Mon, 27 Jun 2022 15:11:12 -0500 Subject: [PATCH] chore: fix issues with Go 1.18 in CI (#416) --- .circleci/config.yml | 2 +- clients/script/script_test.go | 18 ++++++++---------- cmd/influx/global.go | 3 ++- cmd/influx/util.go | 9 --------- cmd/influx/util_go117.go | 16 ---------------- scripts/ci/install-go.sh | 10 +++++----- 6 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 cmd/influx/util.go delete mode 100644 cmd/influx/util_go117.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 679f6d1..2e02f9e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ executors: # NOTE: To upgrade the Go version, first push the upgrade to the cross-builder Dockerfile in the edge repo, # then update the version here to match. Until we finish the migration to using the cross-builder image, # you'll also need to update references to `cimg/go` and `GO_VERSION` in this file. - - image: quay.io/influxdb/cross-builder:go1.18.3-c75d304717395a43913dcc3d576d4f3545375253 + - image: quay.io/influxdb/cross-builder:go1.18.3-9a328a73f91e192f00c7645fef1b5d703e120ea2 resource_class: medium linux-amd64: machine: diff --git a/clients/script/script_test.go b/clients/script/script_test.go index d4c3659..34d9017 100644 --- a/clients/script/script_test.go +++ b/clients/script/script_test.go @@ -67,9 +67,8 @@ func Test_SimpleCreate(t *testing.T) { require.NoError(t, client.Create(context.Background(), ¶ms)) } -func strFactory(arg interface{}) *string { - val := (arg.(string)) // Docker image runs Go 1.17, so we can't use generics here. - return &val +func ptrFactory[T any](arg T) *T { + return &arg } func Test_SimpleList(t *testing.T) { @@ -78,21 +77,20 @@ func Test_SimpleList(t *testing.T) { ctrl := gomock.NewController(t) scriptsApi := mock.NewMockInvokableScriptsApi(ctrl) - language := api.SCRIPTLANGUAGE_FLUX scripts := []api.Script{{ - Id: strFactory("123456789"), + Id: ptrFactory("123456789"), Name: "simple", - Description: strFactory("First script"), + Description: ptrFactory("First script"), OrgID: "1111111111111", Script: `from(bucket: "sample_data") |> range(start: -10h)`, - Language: &language, + Language: ptrFactory(api.SCRIPTLANGUAGE_FLUX), }, { - Id: strFactory("000000001"), + Id: ptrFactory("000000001"), Name: "another", - Description: strFactory("Second script"), + Description: ptrFactory("Second script"), OrgID: "9111111111119", Script: `from(bucket: "sample_data") |> range(start: -5h)`, - Language: &language, + Language: ptrFactory(api.SCRIPTLANGUAGE_FLUX), }, } diff --git a/cmd/influx/global.go b/cmd/influx/global.go index 43a69e8..680a69f 100644 --- a/cmd/influx/global.go +++ b/cmd/influx/global.go @@ -6,6 +6,7 @@ import ( "io" "net/url" "runtime" + "strings" "github.com/influxdata/influx-cli/v2/api" "github.com/influxdata/influx-cli/v2/clients" @@ -96,7 +97,7 @@ func newApiClient(ctx *cli.Context, configSvc config.Service, injectToken bool) if ctx.IsSet(extraHttpHeaderFlagName) { for _, h := range ctx.StringSlice(extraHttpHeaderFlagName) { - k, v, ok := stringsCut(h, ":") + k, v, ok := strings.Cut(h, ":") if !ok { return nil, fmt.Errorf(`header flag syntax "key:value", missing value in %q`, h) } diff --git a/cmd/influx/util.go b/cmd/influx/util.go deleted file mode 100644 index fb93ab0..0000000 --- a/cmd/influx/util.go +++ /dev/null @@ -1,9 +0,0 @@ -//go:build go1.18 - -package main - -import "strings" - -func stringsCut(s, sep string) (before, after string, found bool) { - return strings.Cut(s, sep) -} diff --git a/cmd/influx/util_go117.go b/cmd/influx/util_go117.go deleted file mode 100644 index 041dbc0..0000000 --- a/cmd/influx/util_go117.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build !go1.18 - -// remove this backward compat shim once we either: -// a) upgrade cross-builder docker image in https://github.com/influxdata/edge/ -// b) switch the CI system for this repo away from using cross-builder docker image. - -package main - -import "strings" - -func stringsCut(s, sep string) (before, after string, found bool) { - if i := strings.Index(s, sep); i >= 0 { - return s[:i], s[i+len(sep):], true - } - return s, "", false -} diff --git a/scripts/ci/install-go.sh b/scripts/ci/install-go.sh index b9448cc..b0d446c 100755 --- a/scripts/ci/install-go.sh +++ b/scripts/ci/install-go.sh @@ -1,22 +1,22 @@ #!/usr/bin/env bash set -eo pipefail -declare -r GO_VERSION=1.18.1 +declare -r GO_VERSION=1.18.3 # Hashes are from the table at https://golang.org/dl/ function go_hash () { case $1 in linux_amd64) - echo b3b815f47ababac13810fc6021eb73d65478e0b2db4b09d348eefad9581a2334 + echo 956f8507b302ab0bb747613695cdae10af99bbd39a90cae522b7c0302cc27245 ;; linux_arm64) - echo 56a91851c97fb4697077abbca38860f735c32b38993ff79b088dac46e4735633 + echo beacbe1441bee4d7978b900136d1d6a71d150f0a9bb77e9d50c822065623a35a ;; mac) - echo 63e5035312a9906c98032d9c73d036b6ce54f8632b194228bd08fe3b9fe4ab01 + echo a23a24c5528671d444328a36a98056902f699a5a211b6ad5db29ca0c012e0085 ;; windows) - echo c30bc3f1f7314a953fe208bd9cd5e24bd9403392a6c556ced3677f9f70f71fe1 + echo 9c46023f3ad0300fcfd1e62f2b6c2dfd9667b1f2f5c7a720b14b792af831f071 ;; esac }