blob: c559496e71b9902a9aff5eea5ce34cbe48a1d75a [file] [log] [blame]
Maros Ondrejickac2f76f42023-02-27 13:22:45 +01001package main
2
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "reflect"
5 "runtime"
6 "strings"
7 "time"
8
9 . "github.com/onsi/ginkgo/v2"
10)
11
adrianvillin28bd8f02024-02-13 06:00:02 -050012// These correspond to names used in yaml config
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010013const (
Adrian Villincee15aa2024-03-14 11:42:55 -040014 vppProxyContainerName = "vpp-proxy"
15 nginxProxyContainerName = "nginx-proxy"
16 nginxServerContainerName = "nginx-server"
adrianvillin28bd8f02024-02-13 06:00:02 -050017 mirroringClientInterfaceName = "hstcln"
18 mirroringServerInterfaceName = "hstsrv"
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010019)
20
Adrian Villincee15aa2024-03-14 11:42:55 -040021var nginxTests = []func(s *NginxSuite){}
22var nginxSoloTests = []func(s *NginxSuite){}
23
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010024type NginxSuite struct {
25 HstSuite
26}
27
Adrian Villincee15aa2024-03-14 11:42:55 -040028func registerNginxTests(tests ...func(s *NginxSuite)) {
29 nginxTests = append(nginxTests, tests...)
30}
31func registerNginxSoloTests(tests ...func(s *NginxSuite)) {
32 nginxSoloTests = append(nginxSoloTests, tests...)
33}
34
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010035func (s *NginxSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020036 s.HstSuite.SetupSuite()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010037 s.loadNetworkTopology("2taps")
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010038 s.loadContainerTopology("nginxProxyAndServer")
39}
40
41func (s *NginxSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020042 s.HstSuite.SetupTest()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010043
44 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020045 var sessionConfig Stanza
46 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010047 newStanza("session").
48 append("enable").
49 append("use-app-socket-api").close()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010050
Filip Tehlar608d0062023-04-28 10:29:47 +020051 cpus := s.AllocateCpus()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010052 // ... for proxy
53 vppProxyContainer := s.getContainerByName(vppProxyContainerName)
Filip Tehlar608d0062023-04-28 10:29:47 +020054 proxyVpp, _ := vppProxyContainer.newVppInstance(cpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010055 s.assertNil(proxyVpp.start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010056
adrianvillin28bd8f02024-02-13 06:00:02 -050057 clientInterface := s.getInterfaceByName(mirroringClientInterfaceName)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010058 s.assertNil(proxyVpp.createTap(clientInterface, 1))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010059
adrianvillin28bd8f02024-02-13 06:00:02 -050060 serverInterface := s.getInterfaceByName(mirroringServerInterfaceName)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010061 s.assertNil(proxyVpp.createTap(serverInterface, 2))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010062
63 nginxContainer := s.getTransientContainerByName(nginxProxyContainerName)
64 nginxContainer.create()
Maros Ondrejicka85396a52023-02-28 12:49:43 +010065
66 values := struct {
67 Proxy string
68 Server string
69 }{
Maros Ondrejickae7625d02023-02-28 16:55:01 +010070 Proxy: clientInterface.peer.ip4AddressString(),
71 Server: serverInterface.ip4AddressString(),
Maros Ondrejicka85396a52023-02-28 12:49:43 +010072 }
73 nginxContainer.createConfig(
74 "/nginx.conf",
75 "./resources/nginx/nginx_proxy_mirroring.conf",
76 values,
77 )
Filip Tehlar56e17cf2024-01-11 17:17:33 +010078 s.assertNil(nginxContainer.start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010079
Florin Corase2415f72023-02-28 14:51:03 -080080 proxyVpp.waitForApp("nginx-", 5)
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010081}
Adrian Villincee15aa2024-03-14 11:42:55 -040082
83var _ = Describe("NginxSuite", Ordered, ContinueOnFailure, func() {
84 var s NginxSuite
85 BeforeAll(func() {
86 s.SetupSuite()
87 })
88 BeforeEach(func() {
89 s.SetupTest()
90 })
91 AfterAll(func() {
92 s.TearDownSuite()
93 })
94 AfterEach(func() {
95 s.TearDownTest()
96 })
97 for _, test := range nginxTests {
98 test := test
99 pc := reflect.ValueOf(test).Pointer()
100 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400101 testName := strings.Split(funcValue.Name(), ".")[2]
102 It(testName, func(ctx SpecContext) {
103 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400104 test(&s)
105 }, SpecTimeout(time.Minute*5))
106 }
107})
108
109var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
110 var s NginxSuite
111 BeforeAll(func() {
112 s.SetupSuite()
113 })
114 BeforeEach(func() {
115 s.SetupTest()
116 })
117 AfterAll(func() {
118 s.TearDownSuite()
119 })
120 AfterEach(func() {
121 s.TearDownTest()
122 })
Adrian Villin637edda2024-05-06 06:55:34 -0400123
Adrian Villincee15aa2024-03-14 11:42:55 -0400124 for _, test := range nginxSoloTests {
125 test := test
126 pc := reflect.ValueOf(test).Pointer()
127 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400128 testName := strings.Split(funcValue.Name(), ".")[2]
129 It(testName, Label("SOLO"), func(ctx SpecContext) {
130 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400131 test(&s)
132 }, SpecTimeout(time.Minute*5))
133 }
134})