Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +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" |
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 ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 12 | SingleTopoContainerVpp = "vpp" |
| 13 | SingleTopoContainerNginx = "nginx" |
| 14 | TapInterfaceName = "htaphost" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 15 | ) |
| 16 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 17 | var noTopoTests = map[string][]func(s *NoTopoSuite){} |
| 18 | var noTopoSoloTests = map[string][]func(s *NoTopoSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 19 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 20 | type NoTopoSuite struct { |
| 21 | HstSuite |
| 22 | } |
| 23 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 24 | func RegisterNoTopoTests(tests ...func(s *NoTopoSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 25 | noTopoTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 26 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 27 | func RegisterNoTopoSoloTests(tests ...func(s *NoTopoSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 28 | noTopoSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 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() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 33 | s.LoadNetworkTopology("tap") |
| 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. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [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 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 47 | container := s.GetContainerByName(SingleTopoContainerVpp) |
| 48 | vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig) |
| 49 | s.AssertNil(vpp.Start()) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 50 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 51 | tapInterface := s.GetInterfaceByName(TapInterfaceName) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 52 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [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 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 71 | for filename, tests := range noTopoTests { |
| 72 | for _, test := range tests { |
| 73 | test := test |
| 74 | pc := reflect.ValueOf(test).Pointer() |
| 75 | funcValue := runtime.FuncForPC(pc) |
| 76 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 77 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 78 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 79 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 80 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 81 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 82 | } |
| 83 | }) |
| 84 | |
| 85 | var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 86 | var s NoTopoSuite |
| 87 | BeforeAll(func() { |
| 88 | s.SetupSuite() |
| 89 | }) |
| 90 | BeforeEach(func() { |
| 91 | s.SetupTest() |
| 92 | }) |
| 93 | AfterAll(func() { |
| 94 | s.TearDownSuite() |
| 95 | }) |
| 96 | AfterEach(func() { |
| 97 | s.TearDownTest() |
| 98 | }) |
| 99 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 100 | for filename, tests := range noTopoSoloTests { |
| 101 | for _, test := range tests { |
| 102 | test := test |
| 103 | pc := reflect.ValueOf(test).Pointer() |
| 104 | funcValue := runtime.FuncForPC(pc) |
| 105 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 106 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 107 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 108 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 109 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 110 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 111 | } |
| 112 | }) |