Skip to content

Commit 5af70a7

Browse files
committed
[Test] Add test
1 parent a6ed2ee commit 5af70a7

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package v2
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
7+
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
8+
"github.com/opentelekomcloud/gophertelekomcloud/openstack/swr/v2/policy"
9+
"github.com/opentelekomcloud/gophertelekomcloud/openstack/swr/v2/repositories"
10+
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
11+
)
12+
13+
func TestPolicyLifecycle(t *testing.T) {
14+
client, err := clients.NewSwrV2Client()
15+
th.AssertNoErr(t, err)
16+
17+
// setup org
18+
orgName := "test-acc-org-swr-pol"
19+
dep := dependencies{t: t, client: client}
20+
dep.createOrganization(orgName)
21+
t.Cleanup(func() {
22+
dep.deleteOrganization(orgName)
23+
})
24+
25+
repoName := "test-acc-repo-swr-pol"
26+
dep.createRepository(orgName, repoName)
27+
t.Cleanup(func() {
28+
th.AssertNoErr(t, repositories.Delete(client, orgName, repoName))
29+
})
30+
31+
createOpts := policy.CreateOpts{
32+
Algorithm: "or",
33+
Rules: []policy.Rule{
34+
{
35+
Template: "date_rule",
36+
Params: map[string]string{
37+
"days": "30",
38+
},
39+
TagSelectors: []policy.TagSelector{
40+
{
41+
Kind: "label",
42+
Pattern: "v5",
43+
},
44+
},
45+
},
46+
},
47+
}
48+
49+
id, err := policy.Create(client, orgName, repoName, createOpts)
50+
th.AssertNoErr(t, err)
51+
policyId := strconv.Itoa(id)
52+
t.Cleanup(func() {
53+
th.AssertNoErr(t, policy.Delete(client, orgName, repoName, policyId))
54+
})
55+
56+
retentionPolicy, err := policy.Get(client, orgName, repoName, policyId)
57+
th.AssertEquals(t, "date_rule", retentionPolicy.Rules[0].Template)
58+
59+
found := false
60+
policies, err := policy.List(client, orgName, repoName)
61+
for _, pol := range policies {
62+
if pol.ID == id {
63+
found = true
64+
}
65+
}
66+
th.AssertNoErr(t, err)
67+
th.AssertEquals(t, true, found)
68+
69+
updateOpts := policy.UpdateOpts{
70+
Algorithm: "or",
71+
Rules: []policy.Rule{
72+
{
73+
Template: "date_rule",
74+
Params: map[string]string{
75+
"days": "45",
76+
},
77+
TagSelectors: []policy.TagSelector{
78+
{
79+
Kind: "label",
80+
Pattern: "v5",
81+
},
82+
},
83+
},
84+
},
85+
}
86+
err = policy.Update(client, orgName, repoName, policyId, updateOpts)
87+
th.AssertNoErr(t, err)
88+
89+
updated, err := policy.Get(client, orgName, repoName, policyId)
90+
th.AssertNoErr(t, err)
91+
th.AssertEquals(t, "45", updated.Rules[0].Params["days"])
92+
}

0 commit comments

Comments
 (0)