Skip to content

Commit 2b0975a

Browse files
henrybarretogustavosbarreto
authored andcommitted
tests(gateway): add tests to command that renew certificates
1 parent 72a948e commit 2b0975a

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

gateway/certbot_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,62 @@ func TestCertBot_generateCertificateFromDNS(t *testing.T) {
141141
})
142142
}
143143
}
144+
145+
func TestCertBot_executeRenewCertificates(t *testing.T) {
146+
tests := []struct {
147+
name string
148+
config Config
149+
expected error
150+
expectCalls func(*executorMock.Executor)
151+
}{
152+
{
153+
name: "failed to run the renew command",
154+
config: Config{
155+
Staging: false,
156+
},
157+
expectCalls: func(executorMock *executorMock.Executor) {
158+
executorMock.On("Command", "certbot", "renew").Return(exec.Command("")).Once()
159+
executorMock.On("Run", mock.AnythingOfType("*exec.Cmd")).Return(errors.New("failed to run the renew command")).Once()
160+
},
161+
expected: errors.New("failed to run the renew command"),
162+
},
163+
{
164+
name: "successful renew command execution",
165+
config: Config{
166+
Staging: false,
167+
},
168+
expectCalls: func(executorMock *executorMock.Executor) {
169+
executorMock.On("Command", "certbot", "renew").Return(exec.Command("")).Once()
170+
executorMock.On("Run", mock.AnythingOfType("*exec.Cmd")).Return(nil).Once()
171+
},
172+
expected: nil,
173+
},
174+
{
175+
name: "successful renew command execution in staging",
176+
config: Config{
177+
Staging: true,
178+
},
179+
expectCalls: func(executorMock *executorMock.Executor) {
180+
executorMock.On("Command", "certbot", "renew", "--staging").Return(exec.Command("")).Once()
181+
executorMock.On("Run", mock.AnythingOfType("*exec.Cmd")).Return(nil).Once()
182+
},
183+
expected: nil,
184+
},
185+
}
186+
187+
for _, tc := range tests {
188+
t.Run(tc.name, func(tt *testing.T) {
189+
executorMock := new(executorMock.Executor)
190+
191+
certbot := newCertBot(&tc.config)
192+
certbot.ex = executorMock
193+
194+
tc.expectCalls(executorMock)
195+
196+
err := certbot.executeRenewCertificates()
197+
assert.Equal(tt, tc.expected, err)
198+
199+
executorMock.AssertExpectations(t)
200+
})
201+
}
202+
}

0 commit comments

Comments
 (0)