Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 1 | package main |
| 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 | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 13 | vppProxyContainerName = "vpp-proxy" |
| 14 | nginxProxyContainerName = "nginx-proxy" |
| 15 | nginxServerContainerName = "nginx-server" |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 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 | cee15aa | 2024-03-14 11:42:55 -0400 | [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 | } |
| 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() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 36 | s.loadNetworkTopology("2taps") |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 37 | s.loadContainerTopology("nginxProxyAndServer") |
| 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. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [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 |
| 51 | vppProxyContainer := s.getContainerByName(vppProxyContainerName) |
Adrian Villin | b9464cd | 2024-05-27 09:52:59 -0400 | [diff] [blame] | 52 | proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.allocatedCpus, sessionConfig) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 53 | s.assertNil(proxyVpp.start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 54 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 55 | clientInterface := s.getInterfaceByName(mirroringClientInterfaceName) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 56 | s.assertNil(proxyVpp.createTap(clientInterface, 1)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 57 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 58 | serverInterface := s.getInterfaceByName(mirroringServerInterfaceName) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 59 | s.assertNil(proxyVpp.createTap(serverInterface, 2)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 60 | |
| 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 | }{ |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 68 | Proxy: clientInterface.peer.ip4AddressString(), |
| 69 | Server: serverInterface.ip4AddressString(), |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 70 | } |
| 71 | nginxContainer.createConfig( |
| 72 | "/nginx.conf", |
| 73 | "./resources/nginx/nginx_proxy_mirroring.conf", |
| 74 | values, |
| 75 | ) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 76 | s.assertNil(nginxContainer.start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 77 | |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [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) { |
| 103 | s.log(testName + ": BEGIN") |
| 104 | test(&s) |
| 105 | }, SpecTimeout(suiteTimeout)) |
| 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) { |
| 132 | s.log(testName + ": BEGIN") |
| 133 | test(&s) |
| 134 | }, SpecTimeout(suiteTimeout)) |
| 135 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 136 | } |
| 137 | }) |