-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolicy_group_environments_test.go
105 lines (83 loc) · 3.04 KB
/
policy_group_environments_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
package scalr
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPolicyGroupEnvironmentsCreate(t *testing.T) {
// TODO: delete skip after SCALRCORE-19891
t.Skip("Works with personal token but does not work with github action token.")
client := testClient(t)
ctx := context.Background()
envTest, envTestCleanup := createEnvironment(t, client)
defer envTestCleanup()
policyGroup, policyGroupCleanup := createPolicyGroup(t, client, nil)
defer policyGroupCleanup()
t.Run("with valid options", func(t *testing.T) {
options := PolicyGroupEnvironmentsCreateOptions{
PolicyGroupID: policyGroup.ID,
PolicyGroupEnvironments: []*PolicyGroupEnvironment{{ID: envTest.ID}},
}
err := client.PolicyGroupEnvironments.Create(ctx, options)
require.NoError(t, err)
// Get a refreshed view from the API.
refreshed, err := client.PolicyGroups.Read(ctx, policyGroup.ID)
require.NoError(t, err)
for _, item := range refreshed.Environments {
assert.Equal(t, envTest.ID, item.ID)
}
func() {
client.PolicyGroupEnvironments.Delete(
ctx,
PolicyGroupEnvironmentDeleteOptions{
PolicyGroupID: policyGroup.ID,
EnvironmentID: envTest.ID,
},
)
}()
})
t.Run("with empty options", func(t *testing.T) {
err := client.PolicyGroupEnvironments.Create(ctx, PolicyGroupEnvironmentsCreateOptions{})
assert.EqualError(t, err, "invalid value for policy group ID")
})
t.Run("when options has an invalid environment", func(t *testing.T) {
var envID = "env-123"
options := PolicyGroupEnvironmentsCreateOptions{
PolicyGroupID: policyGroup.ID,
PolicyGroupEnvironments: []*PolicyGroupEnvironment{{ID: envID}},
}
err := client.PolicyGroupEnvironments.Create(ctx, options)
assert.NotEmpty(t, err)
})
}
func TestPolicyGroupEnvironmentDelete(t *testing.T) {
// TODO: delete skip after SCALRCORE-19891
t.Skip("Works with personal token but does not work with github action token.")
client := testClient(t)
ctx := context.Background()
envTest, envTestCleanup := createEnvironment(t, client)
policyGroup, policyGroupCleanup := createPolicyGroup(t, client, nil)
policyGroupEnvironmentLinkCleanup := linkPolicyGroupToEnvironment(t, client, policyGroup, envTest)
defer policyGroupEnvironmentLinkCleanup()
defer policyGroupCleanup()
defer envTestCleanup()
t.Run("with valid options", func(t *testing.T) {
err := client.PolicyGroupEnvironments.Delete(ctx, PolicyGroupEnvironmentDeleteOptions{
PolicyGroupID: policyGroup.ID,
EnvironmentID: envTest.ID,
})
require.NoError(t, err)
// Get a refreshed view from the API.
refreshed, err := client.PolicyGroups.Read(ctx, policyGroup.ID)
require.NoError(t, err)
assert.Empty(t, refreshed.Environments)
})
t.Run("without a valid policy group ID", func(t *testing.T) {
err := client.PolicyGroupEnvironments.Delete(ctx, PolicyGroupEnvironmentDeleteOptions{
PolicyGroupID: badIdentifier,
EnvironmentID: envTest.ID,
})
assert.EqualError(t, err, "invalid value for policy group ID")
})
}