blob: 260fc1d681ddf1a0e53f20d2ffee5e6c80d7b5c4 [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"
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 (
12 singleTopoContainerVpp = "vpp"
13 singleTopoContainerNginx = "nginx"
14 tapInterfaceName = "htaphost"
15)
16
17var noTopoTests = []func(s *NoTopoSuite){}
18var noTopoSoloTests = []func(s *NoTopoSuite){}
19
Filip Tehlarc204c872022-12-21 08:59:16 +010020type NoTopoSuite struct {
21 HstSuite
22}
23
Adrian Villincee15aa2024-03-14 11:42:55 -040024func registerNoTopoTests(tests ...func(s *NoTopoSuite)) {
25 noTopoTests = append(noTopoTests, tests...)
26}
27func registerNoTopoSoloTests(tests ...func(s *NoTopoSuite)) {
28 noTopoSoloTests = append(noTopoSoloTests, tests...)
29}
30
Filip Tehlarc204c872022-12-21 08:59:16 +010031func (s *NoTopoSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020032 s.HstSuite.SetupSuite()
Maros Ondrejicka40cba402023-02-23 13:19:15 +010033 s.loadNetworkTopology("tap")
Filip Tehlarc204c872022-12-21 08:59:16 +010034 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.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010043 newStanza("session").
44 append("enable").
45 append("use-app-socket-api").close()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010046
47 container := s.getContainerByName(singleTopoContainerVpp)
Adrian Villinb9464cd2024-05-27 09:52:59 -040048 vpp, _ := container.newVppInstance(container.allocatedCpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010049 s.assertNil(vpp.start())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010050
adrianvillin28bd8f02024-02-13 06:00:02 -050051 tapInterface := s.getInterfaceByName(tapInterfaceName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010052
Filip Tehlar56e17cf2024-01-11 17:17:33 +010053 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
71 for _, test := range noTopoTests {
72 test := test
73 pc := reflect.ValueOf(test).Pointer()
74 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -040075 testName := strings.Split(funcValue.Name(), ".")[2]
76 It(testName, func(ctx SpecContext) {
77 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -040078 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -040079 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -040080 }
81})
82
83var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
84 var s NoTopoSuite
85 BeforeAll(func() {
86 s.SetupSuite()
87 })
88 BeforeEach(func() {
89 s.SetupTest()
90 })
91 AfterAll(func() {
92 s.TearDownSuite()
93 })
94 AfterEach(func() {
95 s.TearDownTest()
96 })
97
98 for _, test := range noTopoSoloTests {
99 test := test
100 pc := reflect.ValueOf(test).Pointer()
101 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400102 testName := strings.Split(funcValue.Name(), ".")[2]
103 It(testName, Label("SOLO"), func(ctx SpecContext) {
104 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400105 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -0400106 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -0400107 }
108})