diff options
author | Adrian Villin <avillin@cisco.com> | 2024-06-07 06:45:48 -0400 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2024-06-10 16:42:38 +0000 |
commit | 681ff3a02a47ff453df84da5e5f4359f1d60d055 (patch) | |
tree | 2234459b7d32c1f869338c35b9f0fdd8a822eaae /extras/hs-test | |
parent | 3def24bc489d879a05ced49d2dddfe909c489623 (diff) |
hs-test: added filenames to test names
- It is now possible to only run tests that are in a certain file
Type: test
Change-Id: I41665dd2bc0942c283be36a5af3e560fd65e9d03
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test')
-rw-r--r-- | extras/hs-test/README.rst | 24 | ||||
-rw-r--r-- | extras/hs-test/framework_test.go | 7 | ||||
-rw-r--r-- | extras/hs-test/suite_nginx_test.go | 49 | ||||
-rw-r--r-- | extras/hs-test/suite_no_topo_test.go | 48 | ||||
-rw-r--r-- | extras/hs-test/suite_ns_test.go | 48 | ||||
-rw-r--r-- | extras/hs-test/suite_tap_test.go | 48 | ||||
-rw-r--r-- | extras/hs-test/suite_veth_test.go | 48 |
7 files changed, 162 insertions, 110 deletions
diff --git a/extras/hs-test/README.rst b/extras/hs-test/README.rst index 1dc1039b33f..a88251af617 100644 --- a/extras/hs-test/README.rst +++ b/extras/hs-test/README.rst @@ -89,6 +89,30 @@ This can be put in file ``extras/hs-test/my_test.go`` and run with command ``mak s.log(result) } + +Filtering test cases +-------------------- + +The framework allows us to filter test cases in a few different ways, using ``make test TEST=``: +* Suite name +* File name +* Test name +* All of the above as long as they are ordered properly, e.g. ``make test TEST=VethsSuite.http_test.go.HeaderServerTest`` + +**Names are case sensitive!** + +Names don't have to be complete, as long as they are last: +This is valid and will run all tests in every ``http`` file (if there is more than one): +``make test TEST=VethsSuite.http`` +This is not valid: +``make test TEST=Veths.http`` + +They can also be left out: +``make test TEST=http_test.go`` will run every test in ``http_test.go`` +``make test TEST=Nginx`` will run everything that has 'Nginx' in its name - suites, files and tests. +``make test TEST=HeaderServerTest`` will only run the header server test + + Modifying the framework ----------------------- diff --git a/extras/hs-test/framework_test.go b/extras/hs-test/framework_test.go index 8cbf936f026..8d7e2edfd13 100644 --- a/extras/hs-test/framework_test.go +++ b/extras/hs-test/framework_test.go @@ -1,6 +1,8 @@ package main import ( + "path/filepath" + "runtime" "testing" "time" @@ -10,6 +12,11 @@ import ( var suiteTimeout time.Duration +func getTestFilename() string { + _, filename, _, _ := runtime.Caller(2) + return filepath.Base(filename) +} + func TestHst(t *testing.T) { if *isVppDebug { // 30 minute timeout so that the framework won't timeout while debugging diff --git a/extras/hs-test/suite_nginx_test.go b/extras/hs-test/suite_nginx_test.go index 4c6e9dbb309..7caf16ef432 100644 --- a/extras/hs-test/suite_nginx_test.go +++ b/extras/hs-test/suite_nginx_test.go @@ -17,18 +17,18 @@ const ( mirroringServerInterfaceName = "hstsrv" ) -var nginxTests = []func(s *NginxSuite){} -var nginxSoloTests = []func(s *NginxSuite){} +var nginxTests = map[string][]func(s *NginxSuite){} +var nginxSoloTests = map[string][]func(s *NginxSuite){} type NginxSuite struct { HstSuite } func registerNginxTests(tests ...func(s *NginxSuite)) { - nginxTests = append(nginxTests, tests...) + nginxTests[getTestFilename()] = tests } func registerNginxSoloTests(tests ...func(s *NginxSuite)) { - nginxSoloTests = append(nginxSoloTests, tests...) + nginxSoloTests[getTestFilename()] = tests } func (s *NginxSuite) SetupSuite() { @@ -92,15 +92,18 @@ var _ = Describe("NginxSuite", Ordered, ContinueOnFailure, func() { AfterEach(func() { s.TearDownTest() }) - for _, test := range nginxTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + + for filename, tests := range nginxTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) @@ -119,14 +122,16 @@ var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { s.TearDownTest() }) - for _, test := range nginxSoloTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range nginxSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) diff --git a/extras/hs-test/suite_no_topo_test.go b/extras/hs-test/suite_no_topo_test.go index 260fc1d681d..af0cf9a197a 100644 --- a/extras/hs-test/suite_no_topo_test.go +++ b/extras/hs-test/suite_no_topo_test.go @@ -14,18 +14,18 @@ const ( tapInterfaceName = "htaphost" ) -var noTopoTests = []func(s *NoTopoSuite){} -var noTopoSoloTests = []func(s *NoTopoSuite){} +var noTopoTests = map[string][]func(s *NoTopoSuite){} +var noTopoSoloTests = map[string][]func(s *NoTopoSuite){} type NoTopoSuite struct { HstSuite } func registerNoTopoTests(tests ...func(s *NoTopoSuite)) { - noTopoTests = append(noTopoTests, tests...) + noTopoTests[getTestFilename()] = tests } func registerNoTopoSoloTests(tests ...func(s *NoTopoSuite)) { - noTopoSoloTests = append(noTopoSoloTests, tests...) + noTopoSoloTests[getTestFilename()] = tests } func (s *NoTopoSuite) SetupSuite() { @@ -68,15 +68,17 @@ var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() { s.TearDownTest() }) - for _, test := range noTopoTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range noTopoTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) @@ -95,14 +97,16 @@ var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { s.TearDownTest() }) - for _, test := range noTopoSoloTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range noTopoSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) diff --git a/extras/hs-test/suite_ns_test.go b/extras/hs-test/suite_ns_test.go index 7bdb90b42ae..b4fa7718041 100644 --- a/extras/hs-test/suite_ns_test.go +++ b/extras/hs-test/suite_ns_test.go @@ -15,18 +15,18 @@ const ( serverInterface = "hsrvvpp" ) -var nsTests = []func(s *NsSuite){} -var nsSoloTests = []func(s *NsSuite){} +var nsTests = map[string][]func(s *NsSuite){} +var nsSoloTests = map[string][]func(s *NsSuite){} type NsSuite struct { HstSuite } func registerNsTests(tests ...func(s *NsSuite)) { - nsTests = append(nsTests, tests...) + nsTests[getTestFilename()] = tests } func registerNsSoloTests(tests ...func(s *NsSuite)) { - nsSoloTests = append(nsSoloTests, tests...) + nsSoloTests[getTestFilename()] = tests } func (s *NsSuite) SetupSuite() { @@ -77,15 +77,17 @@ var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() { s.TearDownTest() }) - for _, test := range nsTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range nsTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) @@ -104,14 +106,16 @@ var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { s.TearDownTest() }) - for _, test := range nsSoloTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range nsSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) diff --git a/extras/hs-test/suite_tap_test.go b/extras/hs-test/suite_tap_test.go index cb0653304c3..bb7082de480 100644 --- a/extras/hs-test/suite_tap_test.go +++ b/extras/hs-test/suite_tap_test.go @@ -13,14 +13,14 @@ type TapSuite struct { HstSuite } -var tapTests = []func(s *TapSuite){} -var tapSoloTests = []func(s *TapSuite){} +var tapTests = map[string][]func(s *TapSuite){} +var tapSoloTests = map[string][]func(s *TapSuite){} func registerTapTests(tests ...func(s *TapSuite)) { - tapTests = append(tapTests, tests...) + tapTests[getTestFilename()] = tests } func registerTapSoloTests(tests ...func(s *TapSuite)) { - tapSoloTests = append(tapSoloTests, tests...) + tapSoloTests[getTestFilename()] = tests } func (s *TapSuite) SetupSuite() { @@ -44,15 +44,17 @@ var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() { s.TearDownTest() }) - for _, test := range tapTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range tapTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) @@ -71,14 +73,16 @@ var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { s.TearDownTest() }) - for _, test := range tapSoloTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range tapSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) diff --git a/extras/hs-test/suite_veth_test.go b/extras/hs-test/suite_veth_test.go index 13ef5ef268d..49a36cacb83 100644 --- a/extras/hs-test/suite_veth_test.go +++ b/extras/hs-test/suite_veth_test.go @@ -16,18 +16,18 @@ const ( clientInterfaceName = "cln" ) -var vethTests = []func(s *VethsSuite){} -var vethSoloTests = []func(s *VethsSuite){} +var vethTests = map[string][]func(s *VethsSuite){} +var vethSoloTests = map[string][]func(s *VethsSuite){} type VethsSuite struct { HstSuite } func registerVethTests(tests ...func(s *VethsSuite)) { - vethTests = append(vethTests, tests...) + vethTests[getTestFilename()] = tests } func registerSoloVethTests(tests ...func(s *VethsSuite)) { - vethSoloTests = append(vethSoloTests, tests...) + vethSoloTests[getTestFilename()] = tests } func (s *VethsSuite) SetupSuite() { @@ -101,15 +101,17 @@ var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() { }) // https://onsi.github.io/ginkgo/#dynamically-generating-specs - for _, test := range vethTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range vethTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) @@ -129,14 +131,16 @@ var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { }) // https://onsi.github.io/ginkgo/#dynamically-generating-specs - for _, test := range vethSoloTests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(suiteTimeout)) + for filename, tests := range vethSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(suiteTimeout)) + } } }) |