blob: 4c6e9dbb309fa10e1c4c9024c88ec20cc2f6e60c [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 Villincee15aa2024-03-14 11:42:55 -040020var nginxTests = []func(s *NginxSuite){}
21var nginxSoloTests = []func(s *NginxSuite){}
22
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)) {
28 nginxTests = append(nginxTests, tests...)
29}
30func registerNginxSoloTests(tests ...func(s *NginxSuite)) {
31 nginxSoloTests = append(nginxSoloTests, tests...)
32}
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 })
95 for _, test := range nginxTests {
96 test := test
97 pc := reflect.ValueOf(test).Pointer()
98 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -040099 testName := strings.Split(funcValue.Name(), ".")[2]
100 It(testName, func(ctx SpecContext) {
101 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400102 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -0400103 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -0400104 }
105})
106
107var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
108 var s NginxSuite
109 BeforeAll(func() {
110 s.SetupSuite()
111 })
112 BeforeEach(func() {
113 s.SetupTest()
114 })
115 AfterAll(func() {
116 s.TearDownSuite()
117 })
118 AfterEach(func() {
119 s.TearDownTest()
120 })
Adrian Villin637edda2024-05-06 06:55:34 -0400121
Adrian Villincee15aa2024-03-14 11:42:55 -0400122 for _, test := range nginxSoloTests {
123 test := test
124 pc := reflect.ValueOf(test).Pointer()
125 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400126 testName := strings.Split(funcValue.Name(), ".")[2]
127 It(testName, Label("SOLO"), func(ctx SpecContext) {
128 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400129 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -0400130 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -0400131 }
132})