blob: c02ab8e85357999f86031219c2d4b560b98318c3 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01002
3import (
Adrian Villincee15aa2024-03-14 11:42:55 -04004 "reflect"
5 "runtime"
6 "strings"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01007 "time"
Adrian Villincee15aa2024-03-14 11:42:55 -04008
9 . "github.com/onsi/ginkgo/v2"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010010)
11
12type TapSuite struct {
13 HstSuite
14}
15
Adrian Villin681ff3a2024-06-07 06:45:48 -040016var tapTests = map[string][]func(s *TapSuite){}
17var tapSoloTests = map[string][]func(s *TapSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040018
Adrian Villin4677d922024-06-14 09:32:39 +020019func RegisterTapTests(tests ...func(s *TapSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040020 tapTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040021}
Adrian Villin4677d922024-06-14 09:32:39 +020022func RegisterTapSoloTests(tests ...func(s *TapSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040023 tapSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040024}
25
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010026func (s *TapSuite) SetupSuite() {
27 time.Sleep(1 * time.Second)
Filip Tehlar608d0062023-04-28 10:29:47 +020028 s.HstSuite.SetupSuite()
Adrian Villin4677d922024-06-14 09:32:39 +020029 s.ConfigureNetworkTopology("tap")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010030}
Adrian Villincee15aa2024-03-14 11:42:55 -040031
32var _ = 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 Villin681ff3a2024-06-07 06:45:48 -040047 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 Villin4677d922024-06-14 09:32:39 +020054 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040055 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020056 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040057 }
Adrian Villincee15aa2024-03-14 11:42:55 -040058 }
59})
60
61var _ = 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 Villin681ff3a2024-06-07 06:45:48 -040076 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 Villin4677d922024-06-14 09:32:39 +020083 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040084 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020085 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040086 }
Adrian Villincee15aa2024-03-14 11:42:55 -040087 }
88})