Skip to content

Commit 0634384

Browse files
committed
fix failing test due to same policy set name
1 parent e44d618 commit 0634384

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

policy_set_integration_test.go

+63-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ func TestPolicySetsList(t *testing.T) {
2424

2525
upgradeOrganizationSubscription(t, client, orgTest)
2626

27+
version := createAdminSentinelVersion()
28+
opts := AdminSentinelVersionCreateOptions{
29+
Version: version,
30+
URL: "https://www.hashicorp.com",
31+
SHA: genSha(t),
32+
Official: Bool(false),
33+
Deprecated: Bool(false),
34+
DeprecatedReason: String("Test Reason"),
35+
Enabled: Bool(true),
36+
Beta: Bool(false),
37+
}
38+
sv, err := client.Admin.SentinelVersions.Create(ctx, opts)
39+
require.NoError(t, err)
40+
2741
workspace, workspaceCleanup := createWorkspace(t, client, orgTest)
2842
defer workspaceCleanup()
2943
excludedWorkspace, excludedWorkspaceCleanup := createWorkspace(t, client, orgTest)
@@ -32,7 +46,7 @@ func TestPolicySetsList(t *testing.T) {
3246
options := PolicySetCreateOptions{
3347
Kind: Sentinel,
3448
AgentEnabled: true,
35-
PolicyToolVersion: "0.22.1",
49+
PolicyToolVersion: sv.Version,
3650
Overridable: Bool(true),
3751
}
3852

@@ -42,6 +56,10 @@ func TestPolicySetsList(t *testing.T) {
4256
defer psTestCleanup2()
4357
psTest3, psTestCleanup3 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, nil, OPA)
4458
defer psTestCleanup3()
59+
defer func() {
60+
err := client.Admin.SentinelVersions.Delete(ctx, sv.ID)
61+
require.NoError(t, err)
62+
}()
4563

4664
t.Run("without list options", func(t *testing.T) {
4765
psl, err := client.PolicySets.List(ctx, orgTest.Name, nil)
@@ -51,7 +69,6 @@ func TestPolicySetsList(t *testing.T) {
5169
assert.Contains(t, psl.Items, psTest2)
5270
assert.Contains(t, psl.Items, psTest3)
5371
assert.Equal(t, true, psl.Items[0].AgentEnabled)
54-
assert.Equal(t, "0.22.1", psl.Items[0].PolicyToolVersion)
5572
assert.Equal(t, 1, psl.CurrentPage)
5673
assert.Equal(t, 3, psl.TotalCount)
5774
})
@@ -130,11 +147,30 @@ func TestPolicySetsCreate(t *testing.T) {
130147

131148
upgradeOrganizationSubscription(t, client, orgTest)
132149

150+
version := createAdminSentinelVersion()
151+
opts := AdminSentinelVersionCreateOptions{
152+
Version: version,
153+
URL: "https://www.hashicorp.com",
154+
SHA: genSha(t),
155+
Official: Bool(false),
156+
Deprecated: Bool(false),
157+
DeprecatedReason: String("Test Reason"),
158+
Enabled: Bool(true),
159+
Beta: Bool(false),
160+
}
161+
sv, err := client.Admin.SentinelVersions.Create(ctx, opts)
162+
defer func() {
163+
err := client.Admin.SentinelVersions.Delete(ctx, sv.ID)
164+
require.NoError(t, err)
165+
}()
166+
require.NoError(t, err)
167+
133168
var vcsPolicyID string
134169

135170
t.Run("with valid attributes", func(t *testing.T) {
136171
options := PolicySetCreateOptions{
137-
Name: String("policy-set"),
172+
Name: String(randomString(t)),
173+
PolicyToolVersion: sv.Version,
138174
}
139175

140176
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
@@ -162,10 +198,10 @@ func TestPolicySetsCreate(t *testing.T) {
162198

163199
t.Run("with pinned policy runtime version valid attributes", func(t *testing.T) {
164200
options := PolicySetCreateOptions{
165-
Name: String("policy-set"),
201+
Name: String(randomString(t)),
166202
Kind: Sentinel,
167203
AgentEnabled: true,
168-
PolicyToolVersion: "0.22.1",
204+
PolicyToolVersion: sv.Version,
169205
}
170206

171207
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
@@ -175,15 +211,15 @@ func TestPolicySetsCreate(t *testing.T) {
175211
assert.Equal(t, ps.Description, "")
176212
assert.Equal(t, ps.Kind, Sentinel)
177213
assert.Equal(t, ps.AgentEnabled, true)
178-
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
214+
assert.Equal(t, ps.PolicyToolVersion, sv.Version)
179215
assert.False(t, ps.Global)
180216
})
181217

182218
t.Run("with pinned policy runtime version and missing kind", func(t *testing.T) {
183219
options := PolicySetCreateOptions{
184220
Name: String(randomString(t)),
185221
AgentEnabled: true,
186-
PolicyToolVersion: "0.22.1",
222+
PolicyToolVersion: sv.Version,
187223
Overridable: Bool(true),
188224
}
189225
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
@@ -193,7 +229,7 @@ func TestPolicySetsCreate(t *testing.T) {
193229
assert.Equal(t, ps.Description, "")
194230
assert.Equal(t, ps.Kind, Sentinel)
195231
assert.Equal(t, ps.AgentEnabled, true)
196-
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
232+
assert.Equal(t, ps.PolicyToolVersion, sv.Version)
197233
assert.False(t, ps.Global)
198234
})
199235

@@ -627,10 +663,28 @@ func TestPolicySetsUpdate(t *testing.T) {
627663

628664
upgradeOrganizationSubscription(t, client, orgTest)
629665

666+
version := createAdminSentinelVersion()
667+
opts := AdminSentinelVersionCreateOptions{
668+
Version: version,
669+
URL: "https://www.hashicorp.com",
670+
SHA: genSha(t),
671+
Official: Bool(false),
672+
Deprecated: Bool(false),
673+
DeprecatedReason: String("Test Reason"),
674+
Enabled: Bool(true),
675+
Beta: Bool(false),
676+
}
677+
sv, err := client.Admin.SentinelVersions.Create(ctx, opts)
678+
defer func() {
679+
err := client.Admin.SentinelVersions.Delete(ctx, sv.ID)
680+
require.NoError(t, err)
681+
}()
682+
require.NoError(t, err)
683+
630684
options := PolicySetCreateOptions{
631685
Kind: Sentinel,
632686
AgentEnabled: true,
633-
PolicyToolVersion: "0.22.1",
687+
PolicyToolVersion: sv.Version,
634688
Overridable: Bool(true),
635689
}
636690

0 commit comments

Comments
 (0)