-
Notifications
You must be signed in to change notification settings - Fork 3
/
slack_integration_test.go
145 lines (117 loc) · 3.99 KB
/
slack_integration_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package scalr
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSlackIntegrationsCreate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
env1, deleteEnv1 := createEnvironment(t, client)
defer deleteEnv1()
slackConnection, err := client.SlackIntegrations.GetConnection(ctx, defaultAccountID)
require.NoError(t, err)
if slackConnection.ID == "" {
t.Skip("Scalr instance doesn't have working slack connection.")
}
t.Run("with valid options", func(t *testing.T) {
options := SlackIntegrationCreateOptions{
Name: String("test-" + randomString(t)),
Events: []string{
SlackIntegrationEventRunApprovalRequired,
SlackIntegrationEventRunSuccess,
SlackIntegrationEventRunErrored,
},
ChannelId: String("C123"),
RunMode: String("apply"),
Account: &Account{ID: defaultAccountID},
Connection: slackConnection,
Environments: []*Environment{env1},
}
si, err := client.SlackIntegrations.Create(ctx, options)
require.NoError(t, err)
refreshed, err := client.SlackIntegrations.Read(ctx, si.ID)
require.NoError(t, err)
for _, item := range []*SlackIntegration{
si,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, options.Account, item.Account)
assert.Equal(t, *options.ChannelId, item.ChannelId)
assert.Equal(t, options.Events, item.Events)
assert.Equal(t, *options.RunMode, item.RunMode)
}
err = client.SlackIntegrations.Delete(ctx, si.ID)
require.NoError(t, err)
})
}
func TestSlackIntegrationsUpdate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
env1, deleteEnv1 := createEnvironment(t, client)
defer deleteEnv1()
env2, deleteEnv2 := createEnvironment(t, client)
defer deleteEnv2()
slackConnection, err := client.SlackIntegrations.GetConnection(ctx, defaultAccountID)
require.NoError(t, err)
if slackConnection.ID == "" {
t.Skip("Scalr instance doesn't have working slack connection.")
}
si, deleteSlack := createSlackIntegration(t, client, slackConnection, env1)
defer deleteSlack()
t.Run("with valid options", func(t *testing.T) {
options := SlackIntegrationUpdateOptions{
Name: String("test-" + randomString(t)),
Events: []string{SlackIntegrationEventRunApprovalRequired, SlackIntegrationEventRunErrored},
Environments: []*Environment{env2},
RunMode: String("dry"),
}
si, err := client.SlackIntegrations.Update(ctx, si.ID, options)
require.NoError(t, err)
refreshed, err := client.SlackIntegrations.Read(ctx, si.ID)
require.NoError(t, err)
for _, item := range []*SlackIntegration{
si,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.RunMode, item.RunMode)
assert.Equal(t, options.Events, item.Events)
}
})
}
func TestSlackIntegrationsList(t *testing.T) {
client := testClient(t)
ctx := context.Background()
env1, deleteEnv1 := createEnvironment(t, client)
defer deleteEnv1()
env2, deleteEnv2 := createEnvironment(t, client)
defer deleteEnv2()
slackConnection, err := client.SlackIntegrations.GetConnection(ctx, defaultAccountID)
require.NoError(t, err)
if slackConnection.ID == "" {
t.Skip("Scalr instance doesn't have working slack connection.")
}
si, deleteSlack := createSlackIntegration(t, client, slackConnection, env1)
defer deleteSlack()
si2, deleteSlack2 := createSlackIntegration(t, client, slackConnection, env2)
defer deleteSlack2()
t.Run("with valid options", func(t *testing.T) {
options := SlackIntegrationListOptions{
Filter: &SlackIntegrationFilter{Account: String(defaultAccountID)},
}
sil, err := client.SlackIntegrations.List(ctx, options)
require.NoError(t, err)
assert.Equal(t, 2, sil.TotalCount)
expectedIDs := []string{si.ID, si2.ID}
actualIDs := make([]string, len(sil.Items))
for i, s := range sil.Items {
actualIDs[i] = s.ID
}
assert.ElementsMatch(t, expectedIDs, actualIDs)
})
}