Skip to content

Commit 8b31c6a

Browse files
authored
test: increase test coverage for slackhttp and update (#416)
* test: increase test coverage for slackhttp and update * test: rename and reorder update test functions to match conventions Rename test functions to use full struct name (Test_UpdateNotification_*) and reorder alphabetically by base method name with getter/setter grouping.
1 parent 90cf6bc commit 8b31c6a

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

internal/slackhttp/http_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ func Test_NewHTTPClient(t *testing.T) {
5353
timeout: 120 * time.Second,
5454
expectedTimeout: 120 * time.Second,
5555
},
56+
"Zero timeout uses default timeout": {
57+
timeout: 0,
58+
expectedTimeout: defaultTotalTimeout,
59+
expectedSkipTLSVerify: false,
60+
},
61+
"Custom timeout is used when non-zero": {
62+
timeout: 60 * time.Second,
63+
expectedTimeout: 60 * time.Second,
64+
expectedSkipTLSVerify: false,
65+
},
66+
"SkipTLSVerify false keeps verification enabled": {
67+
skipTLSVerify: false,
68+
expectedSkipTLSVerify: false,
69+
expectedTimeout: defaultTotalTimeout,
70+
},
71+
"Retries zero returns non-retrying transport": {
72+
retries: 0,
73+
expectedRetries: 0,
74+
expectedTimeout: defaultTotalTimeout,
75+
expectedSkipTLSVerify: false,
76+
},
5677
}
5778
for name, tc := range tests {
5879
t.Run(name, func(t *testing.T) {

internal/update/update_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,32 @@ func (m *mockDependency) InstallUpdate(ctx context.Context) error {
5252
return args.Error(0)
5353
}
5454

55-
func Test_Update_HasUpdate(t *testing.T) {
55+
func Test_UpdateNotification_Dependencies(t *testing.T) {
56+
dep := &mockDependency{}
57+
u := &UpdateNotification{
58+
dependencies: []Dependency{dep},
59+
}
60+
require.Len(t, u.Dependencies(), 1)
61+
require.Equal(t, dep, u.Dependencies()[0])
62+
}
63+
64+
func Test_UpdateNotification_SetEnabled(t *testing.T) {
65+
u := &UpdateNotification{}
66+
u.SetEnabled(true)
67+
require.True(t, u.Enabled())
68+
u.SetEnabled(false)
69+
require.False(t, u.Enabled())
70+
}
71+
72+
func Test_UpdateNotification_SetEnv(t *testing.T) {
73+
u := &UpdateNotification{}
74+
u.SetEnv("SLACK_SKIP_UPDATE")
75+
require.Equal(t, "SLACK_SKIP_UPDATE", u.Env())
76+
u.SetEnv("")
77+
require.Equal(t, "", u.Env())
78+
}
79+
80+
func Test_UpdateNotification_HasUpdate(t *testing.T) {
5681
for name, tc := range map[string]struct {
5782
dependencyHasUpdate []bool
5883
expectedReturnValue bool
@@ -111,7 +136,15 @@ func Test_Update_HasUpdate(t *testing.T) {
111136
}
112137
}
113138

114-
func Test_Update_isIgnoredCommand(t *testing.T) {
139+
func Test_UpdateNotification_SetHours(t *testing.T) {
140+
u := &UpdateNotification{}
141+
u.SetHours(48.0)
142+
require.Equal(t, 48.0, u.Hours())
143+
u.SetHours(0)
144+
require.Equal(t, 0.0, u.Hours())
145+
}
146+
147+
func Test_UpdateNotification_isIgnoredCommand(t *testing.T) {
115148
for name, tc := range map[string]struct {
116149
command string
117150
expected bool

0 commit comments

Comments
 (0)