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) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame^] | 77 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 78 | It(testName, func(ctx SpecContext) { |
| 79 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 80 | test(&s) |
| 81 | }, SpecTimeout(time.Minute*5)) |
| 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 | |
| 100 | for _, test := range noTopoSoloTests { |
| 101 | test := test |
| 102 | pc := reflect.ValueOf(test).Pointer() |
| 103 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame^] | 104 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 105 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 106 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 107 | test(&s) |
| 108 | }, SpecTimeout(time.Minute*5)) |
| 109 | } |
| 110 | }) |