blob: 625dca9f3cf5a30b90a9e679755149f435615bad [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
Filip Tehlar608d0062023-04-28 10:29:47 +020048 cpus := s.AllocateCpus()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010049 container := s.getContainerByName(singleTopoContainerVpp)
Filip Tehlar608d0062023-04-28 10:29:47 +020050 vpp, _ := container.newVppInstance(cpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010051 s.assertNil(vpp.start())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010052
adrianvillin28bd8f02024-02-13 06:00:02 -050053 tapInterface := s.getInterfaceByName(tapInterfaceName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010054
Filip Tehlar56e17cf2024-01-11 17:17:33 +010055 s.assertNil(vpp.createTap(tapInterface), "failed to create tap interface")
Filip Tehlarc204c872022-12-21 08:59:16 +010056}
Adrian Villincee15aa2024-03-14 11:42:55 -040057
58var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() {
59 var s NoTopoSuite
60 BeforeAll(func() {
61 s.SetupSuite()
62 })
63 BeforeEach(func() {
64 s.SetupTest()
65 })
66 AfterAll(func() {
67 s.TearDownSuite()
68 })
69 AfterEach(func() {
70 s.TearDownTest()
71 })
72
73 for _, test := range noTopoTests {
74 test := test
75 pc := reflect.ValueOf(test).Pointer()
76 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -040077 testName := strings.Split(funcValue.Name(), ".")[2]
78 It(testName, func(ctx SpecContext) {
79 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -040080 test(&s)
81 }, SpecTimeout(time.Minute*5))
82 }
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
100 for _, test := range noTopoSoloTests {
101 test := test
102 pc := reflect.ValueOf(test).Pointer()
103 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400104 testName := strings.Split(funcValue.Name(), ".")[2]
105 It(testName, Label("SOLO"), func(ctx SpecContext) {
106 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400107 test(&s)
108 }, SpecTimeout(time.Minute*5))
109 }
110})