Skip to content

Commit 6f27af1

Browse files
go 1.24.3 + deprecation fixes + minor tooling updates (#68)
* go 1.24.3 * replace hub with gh * use golangci lint * golangci fmt * ioutil deprecation * remove usage of external errors pkg * w.HeaderMap is deprecated * remove the loops (staticcheck) * error strings should not be capitalized (staticcheck) * ineffectual assignment to err fixes * fix ci
1 parent 077d532 commit 6f27af1

24 files changed

Lines changed: 136 additions & 136 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-go@v2
13+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
14+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v.5.5.0
1515
with:
16-
go-version: '^1.17.5'
16+
go-version: '^1.24.3'
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
19+
with:
20+
version: latest
21+
args: --timeout=5m
1722
- run: make test
1823

.go-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.24.3

.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
version: '2'
3+
linters:
4+
default: standard
5+
disable:
6+
- errcheck
7+
- unused
8+
formatters:
9+
enable:
10+
- gofmt
11+
- goimports

Brewfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
brew 'go'
2-
brew 'hub'
2+
brew 'gh'

Makefile

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,44 @@
11
SHELL = /bin/sh
22

3-
VERSION=1.6.1
3+
VERSION=1.7.0
44
BUILD=`git rev-parse HEAD`
55

66
LDFLAGS=-ldflags "-w -s \
77
-X github.com/Betterment/testtrack-cli/cmds.version=${VERSION} \
88
-X github.com/Betterment/testtrack-cli/cmds.build=${BUILD}"
99

1010
PACKAGES=$$(find . -maxdepth 1 -type d ! -path '.' ! -path './.*' ! -path './vendor' ! -path './dist' ! -path './script' ! -path './doc')
11-
LINTEXCLUDES="123nothingyet123"
1211

1312
all: test
1413

1514
install:
1615
@go install ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack
1716

1817
dist:
19-
@mkdir dist &&\
20-
GOOS=linux GOARCH=amd64 go build -o "dist/testtrack.linux" ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack &&\
21-
GOOS=darwin GOARCH=amd64 go build -o "dist/testtrack.darwin-amd64" ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack &&\
18+
@mkdir dist && \
19+
GOOS=linux GOARCH=amd64 go build -o "dist/testtrack.linux" ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack && \
20+
GOOS=darwin GOARCH=amd64 go build -o "dist/testtrack.darwin-amd64" ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack && \
2221
GOOS=darwin GOARCH=arm64 go build -o "dist/testtrack.darwin-arm64" ${LDFLAGS} github.com/Betterment/testtrack-cli/testtrack
2322

2423
release: distclean dist
25-
@hub release create\
26-
-a dist/testtrack.linux\
27-
-a dist/testtrack.darwin-amd64\
28-
-a dist/testtrack.darwin-arm64\
29-
-m "TestTrack CLI ${VERSION}"\
30-
-t "${BUILD}"\
31-
v${VERSION}
24+
@(gh release view v${VERSION} > /dev/null 2>&1 \
25+
&& echo "v${VERSION} has already been released.") \
26+
|| gh release create v${VERSION} \
27+
dist/testtrack.linux \
28+
dist/testtrack.darwin-amd64 \
29+
dist/testtrack.darwin-arm64 \
30+
--title "TestTrack CLI ${VERSION}" \
31+
--target "${BUILD}" \
32+
--generate-notes
3233

3334
test:
34-
@go install golang.org/x/tools/cmd/goimports@latest
35-
@go install golang.org/x/lint/golint@latest
36-
@GOIMPORTS_RESULT=$$($$(go env GOPATH)/bin/goimports -l ${PACKAGES} | grep -v ${LINTEXCLUDES});\
37-
if [ $$(echo "$$GOIMPORTS_RESULT\c" | head -c1 | wc -c) -ne 0 ];\
38-
then\
39-
echo "Style violations found. Run the following command to fix:";\
40-
echo;\
41-
echo "$$(go env GOPATH)/bin/goimports -w" $$GOIMPORTS_RESULT;\
42-
echo;\
43-
exit 1;\
44-
fi
45-
@go vet ${PACKAGES}
46-
@GOLINT_RESULT=$$($$(go env GOPATH)/bin/golint ${PACKAGES} | grep -v ${LINTEXCLUDES});\
47-
if [ $$(echo "$$GOLINT_RESULT\c" | head -c1 | wc -c) -ne 0 ];\
48-
then\
49-
echo $$GOLINT_RESULT;\
50-
exit 1;\
51-
fi
5235
@go test ${PACKAGES}
5336

37+
lint:
38+
golangci-lint version &>/dev/null || brew install golangci-lint
39+
golangci-lint fmt --verbose
40+
golangci-lint run --verbose --timeout 5m
41+
5442
cover:
5543
@echo "What package do you want a coverage report for? \c"
5644
@read PACKAGE &&\
@@ -68,4 +56,4 @@ clean:
6856
distclean: clean
6957
@rm -rf dist
7058

71-
.PHONY: all build install check clean distclean test
59+
.PHONY: all build install clean distclean test

cmds/generate_build_timestamp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmds
22

33
import (
4-
"io/ioutil"
54
"os"
65
"time"
76

@@ -36,5 +35,5 @@ func generateBuildTimestamp() error {
3635
return err
3736
}
3837

39-
return ioutil.WriteFile("testtrack/build_timestamp", timestamp, 0644)
38+
return os.WriteFile("testtrack/build_timestamp", timestamp, 0644)
4039
}

cmds/init_project.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmds
22

33
import (
4-
"io/ioutil"
54
"log"
65
"os"
76

@@ -40,7 +39,7 @@ func initProject() error {
4039
}
4140
keepfile.Close()
4241

43-
if err := ioutil.WriteFile("testtrack/.gitignore", []byte("build_timestamp\n"), 0644); err != nil {
42+
if err := os.WriteFile("testtrack/.gitignore", []byte("build_timestamp\n"), 0644); err != nil {
4443
log.Fatal(err)
4544
}
4645

fakeassignments/fakeassignments.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package fakeassignments
22

33
import (
4-
"io/ioutil"
54
"os"
65

76
"github.com/Betterment/testtrack-cli/paths"
8-
97
"gopkg.in/yaml.v2"
108
)
119

@@ -20,12 +18,12 @@ func Read() (*map[string]string, error) {
2018
if err != nil {
2119
return nil, err
2220
}
23-
err = ioutil.WriteFile(*configDir+"/assignments.yml", []byte("{}"), 0644)
21+
err = os.WriteFile(*configDir+"/assignments.yml", []byte("{}"), 0644)
2422
if err != nil {
2523
return nil, err
2624
}
2725
}
28-
assignmentsBytes, err := ioutil.ReadFile(*configDir + "/assignments.yml")
26+
assignmentsBytes, err := os.ReadFile(*configDir + "/assignments.yml")
2927
if err != nil {
3028
return nil, err
3129
}
@@ -47,7 +45,7 @@ func Write(assignments *map[string]string) error {
4745
if err != nil {
4846
return err
4947
}
50-
err = ioutil.WriteFile(*configDir+"/assignments.yml", bytes, 0644)
48+
err = os.WriteFile(*configDir+"/assignments.yml", bytes, 0644)
5149
if err != nil {
5250
return err
5351
}

fakeserver/routes.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package fakeserver
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"strings"
99

@@ -341,7 +341,7 @@ func postV1AssignmentOverride(r *http.Request) error {
341341
Variant: r.PostForm.Get("variant"),
342342
}
343343
case strings.HasPrefix(contentType, "application/json"):
344-
requestBytes, err := ioutil.ReadAll(r.Body)
344+
requestBytes, err := io.ReadAll(r.Body)
345345
if err != nil {
346346
return err
347347
}
@@ -353,6 +353,10 @@ func postV1AssignmentOverride(r *http.Request) error {
353353
return fmt.Errorf("got unexpected content type %s", contentType)
354354
}
355355
assignments, err := fakeassignments.Read()
356+
if err != nil {
357+
return err
358+
}
359+
356360
(*assignments)[assignment.SplitName] = assignment.Variant
357361
err = fakeassignments.Write(assignments)
358362
if err != nil {
@@ -366,7 +370,7 @@ func postV2AssignmentOverride(r *http.Request) error {
366370
contentType := r.Header.Get("content-type")
367371
switch {
368372
case strings.HasPrefix(contentType, "application/json"):
369-
requestBytes, err := ioutil.ReadAll(r.Body)
373+
requestBytes, err := io.ReadAll(r.Body)
370374
if err != nil {
371375
return err
372376
}
@@ -380,6 +384,10 @@ func postV2AssignmentOverride(r *http.Request) error {
380384
return fmt.Errorf("got unexpected content type %s", contentType)
381385
}
382386
storedAssignments, err := fakeassignments.Read()
387+
if err != nil {
388+
return err
389+
}
390+
383391
for _, assignment := range assignments {
384392
(*storedAssignments)[assignment.SplitName] = assignment.Variant
385393
}
@@ -453,12 +461,12 @@ func getV1SplitDetail() (interface{}, error) {
453461
Location: "location",
454462
Platform: "platform",
455463
VariantDetails: []v1VariantDetail{
456-
v1VariantDetail{
464+
{
457465
Name: "variant_a",
458466
Description: "this is a fake description",
459467
ScreenshotURL: "https://example.org/a",
460468
},
461-
v1VariantDetail{
469+
{
462470
Name: "variant_b",
463471
Description: "this is another fake description",
464472
ScreenshotURL: "https://example.org/b",

fakeserver/server_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package fakeserver
22

33
import (
44
"bytes"
5-
"io/ioutil"
65
"log"
76
"net/http"
87
"net/http/httptest"
@@ -41,7 +40,7 @@ something_something_enabled: "true"
4140
func TestMain(m *testing.M) {
4241
current, exists := os.LookupEnv("TESTTRACK_FAKE_SERVER_CONFIG_DIR")
4342

44-
dir, err := ioutil.TempDir("", "testtrack-cli")
43+
dir, err := os.MkdirTemp("", "testtrack-cli")
4544
if err != nil {
4645
log.Fatal(err)
4746
}
@@ -53,12 +52,12 @@ func TestMain(m *testing.M) {
5352
}
5453

5554
schemaContent := []byte(testSchema)
56-
if err := ioutil.WriteFile(filepath.Join(schemasDir, "test.yml"), schemaContent, 0644); err != nil {
55+
if err := os.WriteFile(filepath.Join(schemasDir, "test.yml"), schemaContent, 0644); err != nil {
5756
log.Fatal(err)
5857
}
5958

6059
assignmentsContent := []byte(testAssignments)
61-
if err := ioutil.WriteFile(filepath.Join(dir, "assignments.yml"), assignmentsContent, 0644); err != nil {
60+
if err := os.WriteFile(filepath.Join(dir, "assignments.yml"), assignmentsContent, 0644); err != nil {
6261
log.Fatal(err)
6362
}
6463

@@ -230,7 +229,7 @@ func TestCors(t *testing.T) {
230229
h.ServeHTTP(w, request)
231230

232231
require.Equal(t, http.StatusOK, w.Code)
233-
require.Equal(t, "", w.HeaderMap.Get("Access-Control-Allow-Origin"))
232+
require.Equal(t, "", w.Result().Header.Get("Access-Control-Allow-Origin"))
234233
})
235234

236235
t.Run("it passes cors with an allowed origin", func(t *testing.T) {
@@ -243,7 +242,7 @@ func TestCors(t *testing.T) {
243242
h.ServeHTTP(w, request)
244243

245244
require.Equal(t, http.StatusOK, w.Code)
246-
require.Equal(t, "http://www.allowed.com", w.HeaderMap.Get("Access-Control-Allow-Origin"))
245+
require.Equal(t, "http://www.allowed.com", w.Result().Header.Get("Access-Control-Allow-Origin"))
247246
})
248247

249248
t.Run("it passes cors from localhost", func(t *testing.T) {
@@ -256,7 +255,7 @@ func TestCors(t *testing.T) {
256255
h.ServeHTTP(w, request)
257256

258257
require.Equal(t, http.StatusOK, w.Code)
259-
require.Equal(t, "http://localhost:3000", w.HeaderMap.Get("Access-Control-Allow-Origin"))
258+
require.Equal(t, "http://localhost:3000", w.Result().Header.Get("Access-Control-Allow-Origin"))
260259
})
261260

262261
t.Run("it passes cors from loopback ip", func(t *testing.T) {
@@ -269,7 +268,7 @@ func TestCors(t *testing.T) {
269268
h.ServeHTTP(w, request)
270269

271270
require.Equal(t, http.StatusOK, w.Code)
272-
require.Equal(t, "http://127.0.0.1:3000", w.HeaderMap.Get("Access-Control-Allow-Origin"))
271+
require.Equal(t, "http://127.0.0.1:3000", w.Result().Header.Get("Access-Control-Allow-Origin"))
273272
})
274273

275274
os.Unsetenv("TESTTRACK_ALLOWED_ORIGINS")
@@ -305,11 +304,11 @@ func TestPersistAssignmentV2(t *testing.T) {
305304

306305
overrides := v2AssignmentOverrideRequestBody{
307306
Assignments: []v1Assignment{
308-
v1Assignment{
307+
{
309308
SplitName: "test.test_experiment",
310309
Variant: "control",
311310
},
312-
v1Assignment{
311+
{
313312
SplitName: "test.test2_experiment",
314313
Variant: "treatment",
315314
},

0 commit comments

Comments
 (0)