hs-test: add tests repeat option
[vpp.git] / extras / hs-test / suite_nginx_test.go
1 package main
2
3 import (
4         "reflect"
5         "runtime"
6         "strings"
7         "time"
8
9         . "github.com/onsi/ginkgo/v2"
10 )
11
12 // These correspond to names used in yaml config
13 const (
14         vppProxyContainerName        = "vpp-proxy"
15         nginxProxyContainerName      = "nginx-proxy"
16         nginxServerContainerName     = "nginx-server"
17         mirroringClientInterfaceName = "hstcln"
18         mirroringServerInterfaceName = "hstsrv"
19 )
20
21 var nginxTests = []func(s *NginxSuite){}
22 var nginxSoloTests = []func(s *NginxSuite){}
23
24 type NginxSuite struct {
25         HstSuite
26 }
27
28 func registerNginxTests(tests ...func(s *NginxSuite)) {
29         nginxTests = append(nginxTests, tests...)
30 }
31 func registerNginxSoloTests(tests ...func(s *NginxSuite)) {
32         nginxSoloTests = append(nginxSoloTests, tests...)
33 }
34
35 func (s *NginxSuite) SetupSuite() {
36         s.HstSuite.SetupSuite()
37         s.loadNetworkTopology("2taps")
38         s.loadContainerTopology("nginxProxyAndServer")
39 }
40
41 func (s *NginxSuite) SetupTest() {
42         s.HstSuite.SetupTest()
43
44         // Setup test conditions
45         var sessionConfig Stanza
46         sessionConfig.
47                 newStanza("session").
48                 append("enable").
49                 append("use-app-socket-api").close()
50
51         cpus := s.AllocateCpus()
52         // ... for proxy
53         vppProxyContainer := s.getContainerByName(vppProxyContainerName)
54         proxyVpp, _ := vppProxyContainer.newVppInstance(cpus, sessionConfig)
55         s.assertNil(proxyVpp.start())
56
57         clientInterface := s.getInterfaceByName(mirroringClientInterfaceName)
58         s.assertNil(proxyVpp.createTap(clientInterface, 1))
59
60         serverInterface := s.getInterfaceByName(mirroringServerInterfaceName)
61         s.assertNil(proxyVpp.createTap(serverInterface, 2))
62
63         nginxContainer := s.getTransientContainerByName(nginxProxyContainerName)
64         nginxContainer.create()
65
66         values := struct {
67                 Proxy  string
68                 Server string
69         }{
70                 Proxy:  clientInterface.peer.ip4AddressString(),
71                 Server: serverInterface.ip4AddressString(),
72         }
73         nginxContainer.createConfig(
74                 "/nginx.conf",
75                 "./resources/nginx/nginx_proxy_mirroring.conf",
76                 values,
77         )
78         s.assertNil(nginxContainer.start())
79
80         proxyVpp.waitForApp("nginx-", 5)
81 }
82
83 var _ = 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
107 var _ = 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 })