blob: 6df06c7e60e243f358b8b140323d35d50ef1c767 [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)
77 It(strings.Split(funcValue.Name(), ".")[2], func(ctx SpecContext) {
78 test(&s)
79 }, SpecTimeout(time.Minute*5))
80 }
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)
102 It(strings.Split(funcValue.Name(), ".")[2], Label("SOLO"), func(ctx SpecContext) {
103 test(&s)
104 }, SpecTimeout(time.Minute*5))
105 }
106})