Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +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" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 9 | ) |
| 10 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 11 | const ( |
| 12 | singleTopoContainerVpp = "vpp" |
| 13 | singleTopoContainerNginx = "nginx" |
| 14 | tapInterfaceName = "htaphost" |
| 15 | ) |
| 16 | |
| 17 | var noTopoTests = []func(s *NoTopoSuite){} |
| 18 | var noTopoSoloTests = []func(s *NoTopoSuite){} |
| 19 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 20 | type NoTopoSuite struct { |
| 21 | HstSuite |
| 22 | } |
| 23 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 24 | func registerNoTopoTests(tests ...func(s *NoTopoSuite)) { |
| 25 | noTopoTests = append(noTopoTests, tests...) |
| 26 | } |
| 27 | func registerNoTopoSoloTests(tests ...func(s *NoTopoSuite)) { |
| 28 | noTopoSoloTests = append(noTopoSoloTests, tests...) |
| 29 | } |
| 30 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 31 | func (s *NoTopoSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 32 | s.HstSuite.SetupSuite() |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 33 | s.loadNetworkTopology("tap") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 34 | s.loadContainerTopology("single") |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | func (s *NoTopoSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 38 | s.HstSuite.SetupTest() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 39 | |
| 40 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 41 | var sessionConfig Stanza |
| 42 | sessionConfig. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 43 | newStanza("session"). |
| 44 | append("enable"). |
| 45 | append("use-app-socket-api").close() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 46 | |
| 47 | container := s.getContainerByName(singleTopoContainerVpp) |
Adrian Villin | b9464cd | 2024-05-27 09:52:59 -0400 | [diff] [blame] | 48 | vpp, _ := container.newVppInstance(container.allocatedCpus, sessionConfig) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 49 | s.assertNil(vpp.start()) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 50 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 51 | tapInterface := s.getInterfaceByName(tapInterfaceName) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 52 | |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 53 | s.assertNil(vpp.createTap(tapInterface), "failed to create tap interface") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 54 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 55 | |
| 56 | var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() { |
| 57 | var s NoTopoSuite |
| 58 | BeforeAll(func() { |
| 59 | s.SetupSuite() |
| 60 | }) |
| 61 | BeforeEach(func() { |
| 62 | s.SetupTest() |
| 63 | }) |
| 64 | AfterAll(func() { |
| 65 | s.TearDownSuite() |
| 66 | }) |
| 67 | AfterEach(func() { |
| 68 | s.TearDownTest() |
| 69 | }) |
| 70 | |
| 71 | for _, test := range noTopoTests { |
| 72 | test := test |
| 73 | pc := reflect.ValueOf(test).Pointer() |
| 74 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 75 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 76 | It(testName, func(ctx SpecContext) { |
| 77 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 78 | test(&s) |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame^] | 79 | }, SpecTimeout(suiteTimeout)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 80 | } |
| 81 | }) |
| 82 | |
| 83 | var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 84 | var s NoTopoSuite |
| 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 | |
| 98 | for _, test := range noTopoSoloTests { |
| 99 | test := test |
| 100 | pc := reflect.ValueOf(test).Pointer() |
| 101 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 102 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 103 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 104 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 105 | test(&s) |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame^] | 106 | }, SpecTimeout(suiteTimeout)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 107 | } |
| 108 | }) |