Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 4 | "reflect" |
| 5 | "runtime" |
| 6 | "strings" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 7 | "time" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 8 | |
| 9 | . "github.com/onsi/ginkgo/v2" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | type TapSuite struct { |
| 13 | HstSuite |
| 14 | } |
| 15 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 16 | var tapTests = map[string][]func(s *TapSuite){} |
| 17 | var tapSoloTests = map[string][]func(s *TapSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 18 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 19 | func RegisterTapTests(tests ...func(s *TapSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 20 | tapTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 21 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 22 | func RegisterTapSoloTests(tests ...func(s *TapSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 23 | tapSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 24 | } |
| 25 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 26 | func (s *TapSuite) SetupSuite() { |
| 27 | time.Sleep(1 * time.Second) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 28 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 29 | s.ConfigureNetworkTopology("tap") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 30 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 31 | |
| 32 | var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() { |
| 33 | var s TapSuite |
| 34 | BeforeAll(func() { |
| 35 | s.SetupSuite() |
| 36 | }) |
| 37 | BeforeEach(func() { |
| 38 | s.SetupTest() |
| 39 | }) |
| 40 | AfterAll(func() { |
| 41 | s.TearDownSuite() |
| 42 | }) |
| 43 | AfterEach(func() { |
| 44 | s.TearDownTest() |
| 45 | }) |
| 46 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 47 | for filename, tests := range tapTests { |
| 48 | for _, test := range tests { |
| 49 | test := test |
| 50 | pc := reflect.ValueOf(test).Pointer() |
| 51 | funcValue := runtime.FuncForPC(pc) |
| 52 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 53 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 54 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 55 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 56 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 57 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 58 | } |
| 59 | }) |
| 60 | |
| 61 | var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 62 | var s TapSuite |
| 63 | BeforeAll(func() { |
| 64 | s.SetupSuite() |
| 65 | }) |
| 66 | BeforeEach(func() { |
| 67 | s.SetupTest() |
| 68 | }) |
| 69 | AfterAll(func() { |
| 70 | s.TearDownSuite() |
| 71 | }) |
| 72 | AfterEach(func() { |
| 73 | s.TearDownTest() |
| 74 | }) |
| 75 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 76 | for filename, tests := range tapSoloTests { |
| 77 | for _, test := range tests { |
| 78 | test := test |
| 79 | pc := reflect.ValueOf(test).Pointer() |
| 80 | funcValue := runtime.FuncForPC(pc) |
| 81 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 82 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 83 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 84 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 85 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 86 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 87 | } |
| 88 | }) |