blob: 2d1caf152f45582ea5d80b317a9b054c868f821b [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)
101 It(strings.Split(funcValue.Name(), ".")[2], func(ctx SpecContext) {
102 test(&s)
103 }, SpecTimeout(time.Minute*5))
104 }
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 })
121 for _, test := range nginxSoloTests {
122 test := test
123 pc := reflect.ValueOf(test).Pointer()
124 funcValue := runtime.FuncForPC(pc)
125 It(strings.Split(funcValue.Name(), ".")[2], Label("SOLO"), func(ctx SpecContext) {
126 test(&s)
127 }, SpecTimeout(time.Minute*5))
128 }
129})