-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
82 lines (63 loc) · 2.07 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"testing"
"github.com/sendwithus/cloudwatch-cleaner/change"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type mockClient struct {
change.Client
mock.Mock
}
func (m *mockClient) SetRegion(region string) {
m.Called()
}
func (m *mockClient) ListRegions() ([]string, error) {
args := m.Called()
return args.Get(0).([]string), args.Error(1)
}
func (m *mockClient) ListGroups() ([]string, error) {
args := m.Called()
return args.Get(0).([]string), args.Error(1)
}
func (m *mockClient) ListStreams(group string) ([]string, error) {
args := m.Called(group)
return args.Get(0).([]string), args.Error(1)
}
func (m *mockClient) GetRetentionPolicy(group string) (int64, error) {
args := m.Called(group)
return args.Get(0).(int64), args.Error(1)
}
func (m *mockClient) ConvertToInt64(days string) (int64, error) {
args := m.Called(days)
return args.Get(0).(int64), args.Error(1)
}
func (m *mockClient) SetRetentionPolicy(days int64, group string) error {
args := m.Called(group)
return args.Error(0)
}
// Test Run with a retention value of 10 days to trigger the function SetRetentionPolicy
func TestRun(t *testing.T) {
c := &mockClient{}
c.On("SetRegion").Return()
c.On("ListRegions").Return([]string{"us-west-2"}, nil)
c.On("ListGroups").Return([]string{"group-name"}, nil)
c.On("GetRetentionPolicy", mock.Anything).Return(int64(10), nil)
c.On("ConvertToInt64", mock.Anything).Return(int64(30), nil)
c.On("SetRetentionPolicy", mock.Anything).Return(nil)
err := run(c)
assert.Nil(t, err, "Expected no error")
c.AssertExpectations(t)
}
// Test Run with a retention value of 30 days without using the function SetRetentionPolicy
func TestRun30(t *testing.T) {
c := &mockClient{}
c.On("SetRegion").Return()
c.On("ListRegions").Return([]string{"us-west-2"}, nil)
c.On("ListGroups").Return([]string{"group-name"}, nil)
c.On("GetRetentionPolicy", mock.Anything).Return(int64(30), nil)
c.On("ConvertToInt64", mock.Anything).Return(int64(30), nil)
err := run(c)
assert.Nil(t, err, "Expected no error")
c.AssertExpectations(t)
}