blob: 7caf16ef43283853f210b657576621cd57bd53c1 [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"
Adrian Villincee15aa2024-03-14 11:42:55 -04007
8 . "github.com/onsi/ginkgo/v2"
9)
10
adrianvillin28bd8f02024-02-13 06:00:02 -050011// These correspond to names used in yaml config
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010012const (
Adrian Villincee15aa2024-03-14 11:42:55 -040013 vppProxyContainerName = "vpp-proxy"
14 nginxProxyContainerName = "nginx-proxy"
15 nginxServerContainerName = "nginx-server"
adrianvillin28bd8f02024-02-13 06:00:02 -050016 mirroringClientInterfaceName = "hstcln"
17 mirroringServerInterfaceName = "hstsrv"
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010018)
19
Adrian Villin681ff3a2024-06-07 06:45:48 -040020var nginxTests = map[string][]func(s *NginxSuite){}
21var nginxSoloTests = map[string][]func(s *NginxSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040022
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010023type NginxSuite struct {
24 HstSuite
25}
26
Adrian Villincee15aa2024-03-14 11:42:55 -040027func registerNginxTests(tests ...func(s *NginxSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040028 nginxTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040029}
30func registerNginxSoloTests(tests ...func(s *NginxSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040031 nginxSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040032}
33
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010034func (s *NginxSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020035 s.HstSuite.SetupSuite()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010036 s.loadNetworkTopology("2taps")
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010037 s.loadContainerTopology("nginxProxyAndServer")
38}
39
40func (s *NginxSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020041 s.HstSuite.SetupTest()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010042
43 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020044 var sessionConfig Stanza
45 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010046 newStanza("session").
47 append("enable").
48 append("use-app-socket-api").close()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010049
50 // ... for proxy
51 vppProxyContainer := s.getContainerByName(vppProxyContainerName)
Adrian Villinb9464cd2024-05-27 09:52:59 -040052 proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.allocatedCpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010053 s.assertNil(proxyVpp.start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010054
adrianvillin28bd8f02024-02-13 06:00:02 -050055 clientInterface := s.getInterfaceByName(mirroringClientInterfaceName)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010056 s.assertNil(proxyVpp.createTap(clientInterface, 1))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010057
adrianvillin28bd8f02024-02-13 06:00:02 -050058 serverInterface := s.getInterfaceByName(mirroringServerInterfaceName)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010059 s.assertNil(proxyVpp.createTap(serverInterface, 2))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010060
61 nginxContainer := s.getTransientContainerByName(nginxProxyContainerName)
62 nginxContainer.create()
Maros Ondrejicka85396a52023-02-28 12:49:43 +010063
64 values := struct {
65 Proxy string
66 Server string
67 }{
Maros Ondrejickae7625d02023-02-28 16:55:01 +010068 Proxy: clientInterface.peer.ip4AddressString(),
69 Server: serverInterface.ip4AddressString(),
Maros Ondrejicka85396a52023-02-28 12:49:43 +010070 }
71 nginxContainer.createConfig(
72 "/nginx.conf",
73 "./resources/nginx/nginx_proxy_mirroring.conf",
74 values,
75 )
Filip Tehlar56e17cf2024-01-11 17:17:33 +010076 s.assertNil(nginxContainer.start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010077
Florin Corase2415f72023-02-28 14:51:03 -080078 proxyVpp.waitForApp("nginx-", 5)
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010079}
Adrian Villincee15aa2024-03-14 11:42:55 -040080
81var _ = Describe("NginxSuite", Ordered, ContinueOnFailure, func() {
82 var s NginxSuite
83 BeforeAll(func() {
84 s.SetupSuite()
85 })
86 BeforeEach(func() {
87 s.SetupTest()
88 })
89 AfterAll(func() {
90 s.TearDownSuite()
91 })
92 AfterEach(func() {
93 s.TearDownTest()
94 })
Adrian Villin681ff3a2024-06-07 06:45:48 -040095
96 for filename, tests := range nginxTests {
97 for _, test := range tests {
98 test := test
99 pc := reflect.ValueOf(test).Pointer()
100 funcValue := runtime.FuncForPC(pc)
101 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
102 It(testName, func(ctx SpecContext) {
103 s.log(testName + ": BEGIN")
104 test(&s)
105 }, SpecTimeout(suiteTimeout))
106 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400107 }
108})
109
110var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
111 var s NginxSuite
112 BeforeAll(func() {
113 s.SetupSuite()
114 })
115 BeforeEach(func() {
116 s.SetupTest()
117 })
118 AfterAll(func() {
119 s.TearDownSuite()
120 })
121 AfterEach(func() {
122 s.TearDownTest()
123 })
Adrian Villin637edda2024-05-06 06:55:34 -0400124
Adrian Villin681ff3a2024-06-07 06:45:48 -0400125 for filename, tests := range nginxSoloTests {
126 for _, test := range tests {
127 test := test
128 pc := reflect.ValueOf(test).Pointer()
129 funcValue := runtime.FuncForPC(pc)
130 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
131 It(testName, Label("SOLO"), func(ctx SpecContext) {
132 s.log(testName + ": BEGIN")
133 test(&s)
134 }, SpecTimeout(suiteTimeout))
135 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400136 }
137})