-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathsource_ip_test.go
64 lines (51 loc) · 1.98 KB
/
source_ip_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
package acceptance_test
import (
"fmt"
"time"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("c2c traffic source ip", func() {
var (
appName string
orgName string
spaceName string
apps []AppInstance
)
BeforeEach(func() {
appName = fmt.Sprintf("appA-%d", randomGenerator.Int31())
orgName = testConfig.Prefix + "source-traffic-org"
spaceName = testConfig.Prefix + "space"
setupOrgAndSpace(orgName, spaceName)
appCount := 5
By("pushing the test app")
pushAppWithInstanceCount(appName, appCount)
apps = getAppInstances(appName, appCount)
By("adding a network policy")
Expect(cfCLI.AddNetworkPolicy(appName, appName, 8080, "tcp")).To(Succeed())
By(fmt.Sprintf("waiting %s for policies to be created on cells", time.Duration(PolicyWaitTime)))
time.Sleep(PolicyWaitTime)
})
AfterEach(func() {
By("deleting the test org")
Expect(cf.Cf("delete-org", orgName, "-f").Wait(Timeout_Push)).To(gexec.Exit(0))
_, err := cfCLI.CleanupStaleNetworkPolicies()
Expect(err).NotTo(HaveOccurred())
})
It("should be the container's ip", func() {
By("checking when the apps instances are on the same host")
app1, app2 := findTwoInstancesOnTheSameHost(apps)
app2Curl := fmt.Sprintf("curl --fail http://%s:8080/echosourceip", app2.internalIP)
session := cf.Cf("ssh", appName, "-i", app1.index, "-c", app2Curl)
Expect(session.Wait(Timeout_Push)).To(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(ContainSubstring(app1.internalIP))
By("checking when the apps instances are on different same hosts")
app1, app2 = findTwoInstancesOnDifferentHosts(apps)
app2Curl = fmt.Sprintf("curl --fail http://%s:8080/echosourceip", app2.internalIP)
session = cf.Cf("ssh", appName, "-i", app1.index, "-c", app2Curl)
Expect(session.Wait(Timeout_Push)).To(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(ContainSubstring(app1.internalIP))
})
})