Skip to content

Commit 493c5b1

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

File tree

1 file changed

+67
-9
lines changed

1 file changed

+67
-9
lines changed

policy_set_integration_test.go

+67-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ 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(true),
34+
DeprecatedReason: String("Test Reason"),
35+
Enabled: Bool(false),
36+
Beta: Bool(false),
37+
}
38+
sv, err := client.Admin.SentinelVersions.Create(ctx, opts)
39+
//defer client.Admin.SentinelVersions.Delete(ctx, sv.ID)
40+
require.NoError(t, err)
41+
2742
workspace, workspaceCleanup := createWorkspace(t, client, orgTest)
2843
defer workspaceCleanup()
2944
excludedWorkspace, excludedWorkspaceCleanup := createWorkspace(t, client, orgTest)
@@ -32,7 +47,7 @@ func TestPolicySetsList(t *testing.T) {
3247
options := PolicySetCreateOptions{
3348
Kind: Sentinel,
3449
AgentEnabled: true,
35-
PolicyToolVersion: "0.22.1",
50+
PolicyToolVersion: sv.Version,
3651
Overridable: Bool(true),
3752
}
3853

@@ -42,6 +57,10 @@ func TestPolicySetsList(t *testing.T) {
4257
defer psTestCleanup2()
4358
psTest3, psTestCleanup3 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, nil, OPA)
4459
defer psTestCleanup3()
60+
defer func() {
61+
err := client.Admin.SentinelVersions.Delete(ctx, sv.ID)
62+
require.NoError(t, err)
63+
}()
4564

4665
t.Run("without list options", func(t *testing.T) {
4766
psl, err := client.PolicySets.List(ctx, orgTest.Name, nil)
@@ -51,7 +70,7 @@ func TestPolicySetsList(t *testing.T) {
5170
assert.Contains(t, psl.Items, psTest2)
5271
assert.Contains(t, psl.Items, psTest3)
5372
assert.Equal(t, true, psl.Items[0].AgentEnabled)
54-
assert.Equal(t, "0.22.1", psl.Items[0].PolicyToolVersion)
73+
assert.Equal(t, sv.Version, psl.Items[0].PolicyToolVersion)
5574
assert.Equal(t, 1, psl.CurrentPage)
5675
assert.Equal(t, 3, psl.TotalCount)
5776
})
@@ -130,11 +149,31 @@ func TestPolicySetsCreate(t *testing.T) {
130149

131150
upgradeOrganizationSubscription(t, client, orgTest)
132151

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

135173
t.Run("with valid attributes", func(t *testing.T) {
136174
options := PolicySetCreateOptions{
137-
Name: String("policy-set"),
175+
Name: String("policy-set"),
176+
PolicyToolVersion: sv.Version,
138177
}
139178

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

163202
t.Run("with pinned policy runtime version valid attributes", func(t *testing.T) {
164203
options := PolicySetCreateOptions{
165-
Name: String("policy-set"),
204+
Name: String(randomString(t)),
166205
Kind: Sentinel,
167206
AgentEnabled: true,
168-
PolicyToolVersion: "0.22.1",
207+
PolicyToolVersion: sv.Version,
169208
}
170209

171210
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
@@ -175,15 +214,15 @@ func TestPolicySetsCreate(t *testing.T) {
175214
assert.Equal(t, ps.Description, "")
176215
assert.Equal(t, ps.Kind, Sentinel)
177216
assert.Equal(t, ps.AgentEnabled, true)
178-
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
217+
assert.Equal(t, ps.PolicyToolVersion, sv.Version)
179218
assert.False(t, ps.Global)
180219
})
181220

182221
t.Run("with pinned policy runtime version and missing kind", func(t *testing.T) {
183222
options := PolicySetCreateOptions{
184223
Name: String(randomString(t)),
185224
AgentEnabled: true,
186-
PolicyToolVersion: "0.22.1",
225+
PolicyToolVersion: sv.Version,
187226
Overridable: Bool(true),
188227
}
189228
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
@@ -193,7 +232,7 @@ func TestPolicySetsCreate(t *testing.T) {
193232
assert.Equal(t, ps.Description, "")
194233
assert.Equal(t, ps.Kind, Sentinel)
195234
assert.Equal(t, ps.AgentEnabled, true)
196-
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
235+
assert.Equal(t, ps.PolicyToolVersion, sv.Version)
197236
assert.False(t, ps.Global)
198237
})
199238

@@ -627,10 +666,29 @@ func TestPolicySetsUpdate(t *testing.T) {
627666

628667
upgradeOrganizationSubscription(t, client, orgTest)
629668

669+
version := createAdminSentinelVersion()
670+
opts := AdminSentinelVersionCreateOptions{
671+
Version: version,
672+
URL: "https://www.hashicorp.com",
673+
SHA: genSha(t),
674+
Official: Bool(false),
675+
Deprecated: Bool(true),
676+
DeprecatedReason: String("Test Reason"),
677+
Enabled: Bool(false),
678+
Beta: Bool(false),
679+
}
680+
sv, err := client.Admin.SentinelVersions.Create(ctx, opts)
681+
defer func() {
682+
err := client.Admin.SentinelVersions.Delete(ctx, sv.ID)
683+
require.NoError(t, err)
684+
}()
685+
//defer client.Admin.SentinelVersions.Delete(ctx, sv.ID)
686+
require.NoError(t, err)
687+
630688
options := PolicySetCreateOptions{
631689
Kind: Sentinel,
632690
AgentEnabled: true,
633-
PolicyToolVersion: "0.22.1",
691+
PolicyToolVersion: sv.Version,
634692
Overridable: Bool(true),
635693
}
636694

0 commit comments

Comments
 (0)