blob: c48e6fb184539cdb38d88868435352ea8ad3ef45 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Filip Tehlarc204c872022-12-21 08:59:16 +01002
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "reflect"
5 "runtime"
6 "strings"
Adrian Villincee15aa2024-03-14 11:42:55 -04007
8 . "github.com/onsi/ginkgo/v2"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +01009)
10
Adrian Villincee15aa2024-03-14 11:42:55 -040011const (
Adrian Villin4677d922024-06-14 09:32:39 +020012 SingleTopoContainerVpp = "vpp"
13 SingleTopoContainerNginx = "nginx"
14 TapInterfaceName = "htaphost"
Adrian Villincee15aa2024-03-14 11:42:55 -040015)
16
Adrian Villin681ff3a2024-06-07 06:45:48 -040017var noTopoTests = map[string][]func(s *NoTopoSuite){}
18var noTopoSoloTests = map[string][]func(s *NoTopoSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040019
Filip Tehlarc204c872022-12-21 08:59:16 +010020type NoTopoSuite struct {
21 HstSuite
22}
23
Adrian Villin4677d922024-06-14 09:32:39 +020024func RegisterNoTopoTests(tests ...func(s *NoTopoSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040025 noTopoTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040026}
Adrian Villin4677d922024-06-14 09:32:39 +020027func RegisterNoTopoSoloTests(tests ...func(s *NoTopoSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040028 noTopoSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040029}
30
Filip Tehlarc204c872022-12-21 08:59:16 +010031func (s *NoTopoSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020032 s.HstSuite.SetupSuite()
Adrian Villin4677d922024-06-14 09:32:39 +020033 s.LoadNetworkTopology("tap")
34 s.LoadContainerTopology("single")
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010035}
36
37func (s *NoTopoSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020038 s.HstSuite.SetupTest()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010039
40 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020041 var sessionConfig Stanza
42 sessionConfig.
Adrian Villin4677d922024-06-14 09:32:39 +020043 NewStanza("session").
44 Append("enable").
45 Append("use-app-socket-api").Close()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010046
Adrian Villin4677d922024-06-14 09:32:39 +020047 container := s.GetContainerByName(SingleTopoContainerVpp)
48 vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig)
49 s.AssertNil(vpp.Start())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010050
Adrian Villin4677d922024-06-14 09:32:39 +020051 tapInterface := s.GetInterfaceByName(TapInterfaceName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010052
Adrian Villin4677d922024-06-14 09:32:39 +020053 s.AssertNil(vpp.createTap(tapInterface), "failed to create tap interface")
Filip Tehlarc204c872022-12-21 08:59:16 +010054}
Adrian Villincee15aa2024-03-14 11:42:55 -040055
56var _ = 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 Villin681ff3a2024-06-07 06:45:48 -040071 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 Villin4677d922024-06-14 09:32:39 +020078 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040079 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020080 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040081 }
Adrian Villincee15aa2024-03-14 11:42:55 -040082 }
83})
84
85var _ = 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 Villin681ff3a2024-06-07 06:45:48 -0400100 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 Villin4677d922024-06-14 09:32:39 +0200107 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400108 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200109 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400110 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400111 }
112})