forked from cloudfoundry/cf-networking-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy_cleanup_test.go
78 lines (61 loc) · 2.31 KB
/
policy_cleanup_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
package acceptance_test
import (
"fmt"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("policy cleanup", func() {
var (
appA string
orgName string
spaceName string
)
BeforeEach(func() {
appA = fmt.Sprintf("appA-%d", randomGenerator.Int31())
AuthAsAdmin()
orgName = "cleanup-org"
Expect(cfCLI.CreateOrg(orgName)).To(Succeed())
Expect(cfCLI.TargetOrg(orgName)).To(Succeed())
spaceName = "cleanup-space"
Expect(cfCLI.CreateSpace(spaceName, orgName)).To(Succeed())
Expect(cfCLI.TargetSpace(spaceName)).To(Succeed())
pushProxy(appA)
})
AfterEach(func() {
Expect(cf.Cf("delete-org", orgName, "-f").Wait(Timeout_Push)).To(gexec.Exit(0))
_, err := cfCLI.CleanupStaleNetworkPolicies()
Expect(err).NotTo(HaveOccurred())
})
Describe("policies/cleanup endpoint", func() {
It("cleans up stale policies for deleted apps", func() {
By("creating a policy")
Expect(cfCLI.AddNetworkPolicy(appA, appA, 1234, "tcp")).To(Succeed())
appAGuid, err := cfCLI.AppGuid(appA)
Expect(err).NotTo(HaveOccurred())
By("checking that policy exists")
allPolicies, err := cfCLI.Curl("GET", "/networking/v0/external/policies", "")
Expect(err).NotTo(HaveOccurred())
Expect(string(allPolicies)).Should(ContainSubstring(appAGuid))
By("cleaning up stale policies")
stalePolicies, err := cfCLI.CleanupStaleNetworkPolicies()
Expect(err).NotTo(HaveOccurred())
Expect(string(stalePolicies)).ShouldNot(ContainSubstring(appAGuid))
By("checking that policy was not deleted")
allPolicies, err = cfCLI.Curl("GET", "/networking/v0/external/policies", "")
Expect(err).NotTo(HaveOccurred())
Expect(string(allPolicies)).Should(ContainSubstring(appAGuid))
By("deleting app so policy becomes stale")
Expect(cfCLI.Delete(appA)).To(Succeed())
By("cleaning up stale policies")
stalePolicies, err = cfCLI.CleanupStaleNetworkPolicies()
Expect(err).NotTo(HaveOccurred())
Expect(string(stalePolicies)).Should(ContainSubstring(appAGuid))
By("checking that stale policy was deleted")
allPolicies, err = cfCLI.Curl("GET", "/networking/v0/external/policies", "")
Expect(err).NotTo(HaveOccurred())
Expect(string(allPolicies)).ShouldNot(ContainSubstring(appAGuid))
})
})
})