blob: f835262d591940a61e39275d82bb1af45a319316 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Maros Ondrejickac2f76f42023-02-27 13:22:45 +01002
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 Villin4677d922024-06-14 09:32:39 +020013 VppProxyContainerName = "vpp-proxy"
14 NginxProxyContainerName = "nginx-proxy"
15 NginxServerContainerName = "nginx-server"
16 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 Villin4677d922024-06-14 09:32:39 +020027func RegisterNginxTests(tests ...func(s *NginxSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040028 nginxTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040029}
Adrian Villin4677d922024-06-14 09:32:39 +020030func 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()
Adrian Villin4677d922024-06-14 09:32:39 +020036 s.LoadNetworkTopology("2taps")
37 s.LoadContainerTopology("nginxProxyAndServer")
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010038}
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.
Adrian Villin4677d922024-06-14 09:32:39 +020046 NewStanza("session").
47 Append("enable").
48 Append("use-app-socket-api").Close()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010049
50 // ... for proxy
Adrian Villin4677d922024-06-14 09:32:39 +020051 vppProxyContainer := s.GetContainerByName(VppProxyContainerName)
52 proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.AllocatedCpus, sessionConfig)
53 s.AssertNil(proxyVpp.Start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010054
Adrian Villin4677d922024-06-14 09:32:39 +020055 clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName)
56 s.AssertNil(proxyVpp.createTap(clientInterface, 1))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010057
Adrian Villin4677d922024-06-14 09:32:39 +020058 serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName)
59 s.AssertNil(proxyVpp.createTap(serverInterface, 2))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010060
Adrian Villin4677d922024-06-14 09:32:39 +020061 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 }{
Adrian Villin4677d922024-06-14 09:32:39 +020068 Proxy: clientInterface.Peer.Ip4AddressString(),
69 Server: serverInterface.Ip4AddressString(),
Maros Ondrejicka85396a52023-02-28 12:49:43 +010070 }
Adrian Villin4677d922024-06-14 09:32:39 +020071 nginxContainer.CreateConfig(
Maros Ondrejicka85396a52023-02-28 12:49:43 +010072 "/nginx.conf",
73 "./resources/nginx/nginx_proxy_mirroring.conf",
74 values,
75 )
Adrian Villin4677d922024-06-14 09:32:39 +020076 s.AssertNil(nginxContainer.Start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010077
Adrian Villin4677d922024-06-14 09:32:39 +020078 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) {
Adrian Villin4677d922024-06-14 09:32:39 +0200103 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400104 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200105 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400106 }
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) {
Adrian Villin4677d922024-06-14 09:32:39 +0200132 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400133 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200134 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400135 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400136 }
137})