blob: 19a3e1fd288c65b12a43a7af3770f347cbfc7d51 [file] [log] [blame]
Filip Tehlarc204c872022-12-21 08:59:16 +01001package main
2
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "reflect"
5 "runtime"
6 "strings"
7 "time"
8
9 . "github.com/onsi/ginkgo/v2"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010010)
11
Adrian Villincee15aa2024-03-14 11:42:55 -040012const (
13 singleTopoContainerVpp = "vpp"
14 singleTopoContainerNginx = "nginx"
15 tapInterfaceName = "htaphost"
16)
17
18var noTopoTests = []func(s *NoTopoSuite){}
19var noTopoSoloTests = []func(s *NoTopoSuite){}
20
Filip Tehlarc204c872022-12-21 08:59:16 +010021type NoTopoSuite struct {
22 HstSuite
23}
24
Adrian Villincee15aa2024-03-14 11:42:55 -040025func registerNoTopoTests(tests ...func(s *NoTopoSuite)) {
26 noTopoTests = append(noTopoTests, tests...)
27}
28func registerNoTopoSoloTests(tests ...func(s *NoTopoSuite)) {
29 noTopoSoloTests = append(noTopoSoloTests, tests...)
30}
31
Filip Tehlarc204c872022-12-21 08:59:16 +010032func (s *NoTopoSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020033 s.HstSuite.SetupSuite()
Maros Ondrejicka40cba402023-02-23 13:19:15 +010034 s.loadNetworkTopology("tap")
Filip Tehlarc204c872022-12-21 08:59:16 +010035 s.loadContainerTopology("single")
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010036}
37
38func (s *NoTopoSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020039 s.HstSuite.SetupTest()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010040
41 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020042 var sessionConfig Stanza
43 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010044 newStanza("session").
45 append("enable").
46 append("use-app-socket-api").close()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010047
48 container := s.getContainerByName(singleTopoContainerVpp)
Adrian Villinb9464cd2024-05-27 09:52:59 -040049 vpp, _ := container.newVppInstance(container.allocatedCpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010050 s.assertNil(vpp.start())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010051
adrianvillin28bd8f02024-02-13 06:00:02 -050052 tapInterface := s.getInterfaceByName(tapInterfaceName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010053
Filip Tehlar56e17cf2024-01-11 17:17:33 +010054 s.assertNil(vpp.createTap(tapInterface), "failed to create tap interface")
Filip Tehlarc204c872022-12-21 08:59:16 +010055}
Adrian Villincee15aa2024-03-14 11:42:55 -040056
57var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() {
58 var s NoTopoSuite
59 BeforeAll(func() {
60 s.SetupSuite()
61 })
62 BeforeEach(func() {
63 s.SetupTest()
64 })
65 AfterAll(func() {
66 s.TearDownSuite()
67 })
68 AfterEach(func() {
69 s.TearDownTest()
70 })
71
72 for _, test := range noTopoTests {
73 test := test
74 pc := reflect.ValueOf(test).Pointer()
75 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -040076 testName := strings.Split(funcValue.Name(), ".")[2]
77 It(testName, func(ctx SpecContext) {
78 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -040079 test(&s)
80 }, SpecTimeout(time.Minute*5))
81 }
82})
83
84var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
85 var s NoTopoSuite
86 BeforeAll(func() {
87 s.SetupSuite()
88 })
89 BeforeEach(func() {
90 s.SetupTest()
91 })
92 AfterAll(func() {
93 s.TearDownSuite()
94 })
95 AfterEach(func() {
96 s.TearDownTest()
97 })
98
99 for _, test := range noTopoSoloTests {
100 test := test
101 pc := reflect.ValueOf(test).Pointer()
102 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400103 testName := strings.Split(funcValue.Name(), ".")[2]
104 It(testName, Label("SOLO"), func(ctx SpecContext) {
105 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400106 test(&s)
107 }, SpecTimeout(time.Minute*5))
108 }
109})