Skip to content

Commit

Permalink
require go 1.21 + updated linters
Browse files Browse the repository at this point in the history
  • Loading branch information
brainexe committed May 16, 2024
1 parent f3b8ee3 commit e254648
Show file tree
Hide file tree
Showing 32 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion bot/bot_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestBot(t *testing.T) {
}

slackClient, err := client.GetSlackClient(cfg.Slack)
assert.Nil(t, err)
assert.NoError(t, err)

commands := &Commands{}
commands.AddCommand(testCommand2{})
Expand Down
8 changes: 4 additions & 4 deletions bot/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestLoadExampleConfig(t *testing.T) {
cfg, err := Load("../../config.example.yaml")
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, cfg.Slack)

assert.False(t, cfg.Jenkins.IsEnabled())
Expand All @@ -30,7 +30,7 @@ func TestLoadDirectory(t *testing.T) {
cfg, err := Load("../../")

// load root pass == okay
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, cfg.Slack)

// invalid directory
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestLoadFile(t *testing.T) {
// load example file == okay
configPath = path.Join("..", "..", "config.example.yaml")
cfg, err = Load(configPath)
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, cfg.Slack)
assert.Equal(t, "info", cfg.Logger.Level)

Expand All @@ -76,7 +76,7 @@ func TestEnvironment(t *testing.T) {

// load example file == okay
cfg, err := Load("../../config.example.yaml")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, "Europe/Berlin", cfg.Timezone)
assert.Equal(t, "mySlackToken", cfg.Slack.Token)
assert.Equal(t, "mySlackSocketToken", cfg.Slack.SocketToken)
Expand Down
8 changes: 4 additions & 4 deletions bot/interaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestInteraction(t *testing.T) {
time.Sleep(time.Millisecond * 20)

commandsProcessed, err := stats.Get(stats.TotalCommands)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, uint(0), commandsProcessed)
})

Expand All @@ -94,7 +94,7 @@ func TestInteraction(t *testing.T) {
time.Sleep(time.Millisecond * 20)

commandsProcessed, err := stats.Get(stats.TotalCommands)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, uint(0), commandsProcessed)
})

Expand Down Expand Up @@ -124,7 +124,7 @@ func TestInteraction(t *testing.T) {
time.Sleep(time.Millisecond * 20)

commandsProcessed, err := stats.Get(stats.TotalCommands)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, uint(1), commandsProcessed)
})

Expand Down Expand Up @@ -212,6 +212,6 @@ func TestReplaceClickedButton(t *testing.T) {

expected := `{"replace_original":false,"delete_original":false,"metadata":{"event_type":"","event_payload":null},"blocks":[{"type":"actions","elements":[{"type":"button","text":{"type":"plain_text","text":"my text (worked)","emoji":true},"action_id":"reply","style":"danger"}]}]}`

assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, expected, string(jsonString))
}
10 changes: 5 additions & 5 deletions bot/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ func TestStats(t *testing.T) {

Increase("test", 2)
value, err = Get("test")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, value, uint(2))

IncreaseOne("test")
value, err = Get("test")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, value, uint(3))

Set("test", 42)
value, err = Get("test")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, value, uint(42))

Increase("test", int64(1))
Increase("test", int8(1))
Increase("test", 1)
value, err = Get("test")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, value, uint(45))

IncreaseOne("test")
value, err = Get("test")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, value, uint(46))
}
2 changes: 1 addition & 1 deletion bot/storage/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestChainStorage(t *testing.T) {
defer os.RemoveAll(dir)

fileStorage, err := newFileStorage(dir)
assert.Nil(t, err)
assert.NoError(t, err)

storage := NewChainStorage(fileStorage, newMemoryStorage())

Expand Down
2 changes: 1 addition & 1 deletion bot/storage/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestFileStorage(t *testing.T) {
defer os.RemoveAll(dir)

storage, err := newFileStorage(dir)
assert.Nil(t, err)
assert.NoError(t, err)

t.Run("test file", func(t *testing.T) {
testStorage(t, storage)
Expand Down
38 changes: 19 additions & 19 deletions bot/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func testStorage(t *testing.T, storage Storage) {
const collection = "collection"

err = storage.Write(collection, "test-string", "1")
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Write(collection, "test-int", 2)
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Write(collection, "test-map", map[int]float32{12: 5.5})
assert.Nil(t, err)
assert.NoError(t, err)

// read invalid data
err = storage.Read("collection1", "test", &stringValue)
Expand All @@ -32,22 +32,22 @@ func testStorage(t *testing.T, storage Storage) {

// get keys all
keys, err := storage.GetKeys(collection)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Len(t, keys, 3)

keys, err = storage.GetKeys("invalid-collection")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Len(t, keys, 0)

// read valid data
err = storage.Read(collection, "test-string", &stringValue)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, "1", stringValue)
err = storage.Read(collection, "test-int", &intValue)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, 2, intValue)
err = storage.Read(collection, "test-map", &mapValue)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, map[int]float32{12: 5.5}, mapValue)

// expected unmarshall error when accessing wrong data
Expand All @@ -57,39 +57,39 @@ func testStorage(t *testing.T, storage Storage) {
// Atomic
Atomic(func() {
err = storage.Write(collection, "test-int", 1)
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Write(collection, "test-int", 2)
assert.Nil(t, err)
assert.NoError(t, err)
})
var expectedInt int
err = storage.Read(collection, "test-int", &expectedInt)
assert.Equal(t, 2, expectedInt)

// delete
err = storage.Delete(collection, "test-string")
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Delete(collection, "test-int")
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Delete(collection, "test-map")
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Read("collection1", "test-map", &stringValue)
assert.Error(t, err)

// Atomic
Atomic(func() {
err = storage.Write(collection, "test-int2", 1)
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Write(collection, "test-int2", 2)
assert.Nil(t, err)
assert.NoError(t, err)
})
err = storage.Read(collection, "test-int2", &expectedInt)
assert.Equal(t, 2, expectedInt)
assert.Nil(t, err)
assert.NoError(t, err)
err = storage.Delete(collection, "test-int2")
assert.Nil(t, err)
assert.NoError(t, err)

keys, err = storage.GetKeys(collection)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Len(t, keys, 0)

keys, err = GetKeys("../")
Expand All @@ -101,7 +101,7 @@ func TestStorage(t *testing.T) {
t.Run("validate keys", func(t *testing.T) {
var err error
err = validateKey("valid", "also-val-id")
assert.Nil(t, err)
assert.NoError(t, err)

err = validateKey("valid", "not#valid")
assert.EqualError(t, err, "invalid Storage key: not#valid")
Expand Down
6 changes: 3 additions & 3 deletions bot/util/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func TestParseDuration(t *testing.T) {
t.Run("ParseDuration", func(t *testing.T) {
for _, testCase := range parserTestCases {
native, err := time.ParseDuration(testCase.normal)
assert.Nil(t, err)
assert.NoError(t, err)

actualFull, err := ParseDuration(testCase.long)
assert.Nil(t, err)
assert.NoError(t, err)
actualShort, err := ParseDuration(testCase.normal)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, native.String(), actualFull.String())
assert.Equal(t, native.String(), actualShort.String())
Expand Down
2 changes: 1 addition & 1 deletion bot/util/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestTemplate(t *testing.T) {
text := "{{ test }} {{ $users := makeSlice \"2222\"}}{{ $users }} {{ .foo }}"

temp, err := CompileTemplate(text)
assert.Nil(t, err)
assert.NoError(t, err)
finalText, _ := EvalTemplate(temp, map[string]string{"foo": "bar"})

assert.Equal(t, finalText, "foo [2222] bar")
Expand Down
6 changes: 3 additions & 3 deletions client/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestBitbucket(t *testing.T) {
}

client, err := GetBitbucketClient(cfg)
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, client)
})

Expand All @@ -36,7 +36,7 @@ func TestBitbucket(t *testing.T) {

client, err := GetBitbucketClient(cfg)

assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, client)
})

Expand All @@ -48,7 +48,7 @@ func TestBitbucket(t *testing.T) {

client, err := GetBitbucketClient(cfg)

assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, client)
})
}
2 changes: 1 addition & 1 deletion client/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestHttp(t *testing.T) {

client := GetHTTPClient()
resp, err := client.Get(server.URL)
assert.Nil(t, err)
assert.NoError(t, err)
defer resp.Body.Close()

bodyBytes, _ := io.ReadAll(resp.Body)
Expand Down
2 changes: 1 addition & 1 deletion client/vcs/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestBitbucketLoader(t *testing.T) {
}

branches, err := fetcher.LoadBranches()
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, []string{"master", "release"}, branches)
})

Expand Down
2 changes: 1 addition & 1 deletion client/vcs/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestGitLoader(t *testing.T) {

branches, err := fetcher.LoadBranches()
assert.GreaterOrEqual(t, len(branches), 1)
assert.Nil(t, err)
assert.NoError(t, err)
})

t.Run("Load branches with invalid repoURL", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/vcs/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ func TestNullLoader(t *testing.T) {
t.Run("Load branches with null loader", func(t *testing.T) {
branches, err := fetcher.LoadBranches()
assert.Len(t, branches, 0)
assert.Nil(t, err)
assert.NoError(t, err)
})
}
8 changes: 4 additions & 4 deletions client/vcs/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGetMatchingBranches(t *testing.T) {
t.Run("Not found", func(t *testing.T) {
actual, err := GetMatchingBranch("this-might-be-a-branch")
assert.Equal(t, "this-might-be-a-branch", actual)
assert.Nil(t, err)
assert.NoError(t, err)
})

t.Run("Not unique", func(t *testing.T) {
Expand All @@ -91,14 +91,14 @@ func TestGetMatchingBranches(t *testing.T) {
t.Run("Test unique branches", func(t *testing.T) {
actual, err := GetMatchingBranch("master")
assert.Equal(t, "master", actual)
assert.Nil(t, err)
assert.NoError(t, err)

actual, err = GetMatchingBranch("PROJ-1235")
assert.Equal(t, "bugfix/PROJ-1235-fixed", actual)
assert.Nil(t, err)
assert.NoError(t, err)

actual, err = GetMatchingBranch("feature/PROJ-1234-do-something")
assert.Equal(t, "feature/PROJ-1234-do-something", actual)
assert.Nil(t, err)
assert.NoError(t, err)
})
}
2 changes: 1 addition & 1 deletion cmd/cli/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAll(t *testing.T) {

testURL := tester.FakeServerURL + "command?command=reply%20X"
r, err := http.Get(testURL) //nolint:gosec
assert.Nil(t, err)
assert.NoError(t, err)

resp, _ := io.ReadAll(r.Body)
defer r.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion command/add_button_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func TestAddButton(t *testing.T) {

t.Run("Test help", func(t *testing.T) {
help := command.GetHelp()
assert.Equal(t, 1, len(help))
assert.Len(t, help, 1)
})
}
Loading

0 comments on commit e254648

Please sign in to comment.