bb7082de480645979e6d098a4d95434e6236e55d
[vpp.git] / extras / hs-test / suite_tap_test.go
1 package main
2
3 import (
4         "reflect"
5         "runtime"
6         "strings"
7         "time"
8
9         . "github.com/onsi/ginkgo/v2"
10 )
11
12 type TapSuite struct {
13         HstSuite
14 }
15
16 var tapTests = map[string][]func(s *TapSuite){}
17 var tapSoloTests = map[string][]func(s *TapSuite){}
18
19 func registerTapTests(tests ...func(s *TapSuite)) {
20         tapTests[getTestFilename()] = tests
21 }
22 func registerTapSoloTests(tests ...func(s *TapSuite)) {
23         tapSoloTests[getTestFilename()] = tests
24 }
25
26 func (s *TapSuite) SetupSuite() {
27         time.Sleep(1 * time.Second)
28         s.HstSuite.SetupSuite()
29         s.configureNetworkTopology("tap")
30 }
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
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) {
54                                 s.log(testName + ": BEGIN")
55                                 test(&s)
56                         }, SpecTimeout(suiteTimeout))
57                 }
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
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) {
83                                 s.log(testName + ": BEGIN")
84                                 test(&s)
85                         }, SpecTimeout(suiteTimeout))
86                 }
87         }
88 })