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