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" |
| 7 | "time" |
| 8 | |
| 9 | . "github.com/onsi/ginkgo/v2" |
| 10 | ) |
| 11 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 12 | // These correspond to names used in yaml config |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 13 | const ( |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 14 | vppProxyContainerName = "vpp-proxy" |
| 15 | nginxProxyContainerName = "nginx-proxy" |
| 16 | nginxServerContainerName = "nginx-server" |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 17 | mirroringClientInterfaceName = "hstcln" |
| 18 | mirroringServerInterfaceName = "hstsrv" |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 19 | ) |
| 20 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 21 | var nginxTests = []func(s *NginxSuite){} |
| 22 | var nginxSoloTests = []func(s *NginxSuite){} |
| 23 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 24 | type NginxSuite struct { |
| 25 | HstSuite |
| 26 | } |
| 27 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 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 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 35 | func (s *NginxSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 36 | s.HstSuite.SetupSuite() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 37 | s.loadNetworkTopology("2taps") |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 38 | s.loadContainerTopology("nginxProxyAndServer") |
| 39 | } |
| 40 | |
| 41 | func (s *NginxSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 42 | s.HstSuite.SetupTest() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 43 | |
| 44 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 45 | var sessionConfig Stanza |
| 46 | sessionConfig. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 47 | newStanza("session"). |
| 48 | append("enable"). |
| 49 | append("use-app-socket-api").close() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 50 | |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 51 | cpus := s.AllocateCpus() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 52 | // ... for proxy |
| 53 | vppProxyContainer := s.getContainerByName(vppProxyContainerName) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 54 | proxyVpp, _ := vppProxyContainer.newVppInstance(cpus, sessionConfig) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 55 | s.assertNil(proxyVpp.start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 56 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 57 | clientInterface := s.getInterfaceByName(mirroringClientInterfaceName) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 58 | s.assertNil(proxyVpp.createTap(clientInterface, 1)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 59 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 60 | serverInterface := s.getInterfaceByName(mirroringServerInterfaceName) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 61 | s.assertNil(proxyVpp.createTap(serverInterface, 2)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 62 | |
| 63 | nginxContainer := s.getTransientContainerByName(nginxProxyContainerName) |
| 64 | nginxContainer.create() |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 65 | |
| 66 | values := struct { |
| 67 | Proxy string |
| 68 | Server string |
| 69 | }{ |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 70 | Proxy: clientInterface.peer.ip4AddressString(), |
| 71 | Server: serverInterface.ip4AddressString(), |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 72 | } |
| 73 | nginxContainer.createConfig( |
| 74 | "/nginx.conf", |
| 75 | "./resources/nginx/nginx_proxy_mirroring.conf", |
| 76 | values, |
| 77 | ) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 78 | s.assertNil(nginxContainer.start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 79 | |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 80 | proxyVpp.waitForApp("nginx-", 5) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 81 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 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) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 101 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 102 | It(testName, func(ctx SpecContext) { |
| 103 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 104 | test(&s) |
| 105 | }, SpecTimeout(time.Minute*5)) |
| 106 | } |
| 107 | }) |
| 108 | |
| 109 | var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 110 | var s NginxSuite |
| 111 | BeforeAll(func() { |
| 112 | s.SetupSuite() |
| 113 | }) |
| 114 | BeforeEach(func() { |
| 115 | s.SetupTest() |
| 116 | }) |
| 117 | AfterAll(func() { |
| 118 | s.TearDownSuite() |
| 119 | }) |
| 120 | AfterEach(func() { |
| 121 | s.TearDownTest() |
| 122 | }) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 123 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 124 | for _, test := range nginxSoloTests { |
| 125 | test := test |
| 126 | pc := reflect.ValueOf(test).Pointer() |
| 127 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 128 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 129 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 130 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 131 | test(&s) |
| 132 | }, SpecTimeout(time.Minute*5)) |
| 133 | } |
| 134 | }) |