Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 1 | package hst |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 2 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "reflect" |
| 5 | "runtime" |
| 6 | "strings" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 7 | |
| 8 | . "github.com/onsi/ginkgo/v2" |
| 9 | ) |
| 10 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 11 | // These correspond to names used in yaml config |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 12 | const ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 13 | VppProxyContainerName = "vpp-proxy" |
| 14 | NginxProxyContainerName = "nginx-proxy" |
| 15 | NginxServerContainerName = "nginx-server" |
| 16 | MirroringClientInterfaceName = "hstcln" |
| 17 | MirroringServerInterfaceName = "hstsrv" |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 18 | ) |
| 19 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 20 | var nginxTests = map[string][]func(s *NginxSuite){} |
| 21 | var nginxSoloTests = map[string][]func(s *NginxSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 22 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 23 | type NginxSuite struct { |
| 24 | HstSuite |
| 25 | } |
| 26 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 27 | func RegisterNginxTests(tests ...func(s *NginxSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 28 | nginxTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 29 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 30 | func RegisterNginxSoloTests(tests ...func(s *NginxSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 31 | nginxSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 34 | func (s *NginxSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 35 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 36 | s.LoadNetworkTopology("2taps") |
| 37 | s.LoadContainerTopology("nginxProxyAndServer") |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | func (s *NginxSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 41 | s.HstSuite.SetupTest() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 42 | |
| 43 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 44 | var sessionConfig Stanza |
| 45 | sessionConfig. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 46 | NewStanza("session"). |
| 47 | Append("enable"). |
| 48 | Append("use-app-socket-api").Close() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 49 | |
| 50 | // ... for proxy |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 51 | vppProxyContainer := s.GetContainerByName(VppProxyContainerName) |
| 52 | proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.AllocatedCpus, sessionConfig) |
| 53 | s.AssertNil(proxyVpp.Start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 54 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 55 | clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName) |
| 56 | s.AssertNil(proxyVpp.createTap(clientInterface, 1)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 57 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 58 | serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName) |
| 59 | s.AssertNil(proxyVpp.createTap(serverInterface, 2)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 60 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 61 | nginxContainer := s.GetTransientContainerByName(NginxProxyContainerName) |
| 62 | nginxContainer.Create() |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 63 | |
| 64 | values := struct { |
| 65 | Proxy string |
| 66 | Server string |
| 67 | }{ |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 68 | Proxy: clientInterface.Peer.Ip4AddressString(), |
| 69 | Server: serverInterface.Ip4AddressString(), |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 70 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 71 | nginxContainer.CreateConfig( |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 72 | "/nginx.conf", |
| 73 | "./resources/nginx/nginx_proxy_mirroring.conf", |
| 74 | values, |
| 75 | ) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 76 | s.AssertNil(nginxContainer.Start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 77 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 78 | proxyVpp.WaitForApp("nginx-", 5) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 79 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 80 | |
| 81 | var _ = 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 Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 95 | |
| 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 Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 103 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 104 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 105 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 106 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 107 | } |
| 108 | }) |
| 109 | |
| 110 | var _ = 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 Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 124 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 125 | 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 Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 132 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 133 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 134 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 135 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 136 | } |
| 137 | }) |