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>
This commit is contained in:
Adrian Villin
2024-06-07 06:45:48 -04:00
committed by Dave Wallace
parent 3def24bc48
commit 681ff3a02a
7 changed files with 162 additions and 110 deletions

View File

@ -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
-----------------------

View File

@ -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

View File

@ -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,16 +92,19 @@ var _ = Describe("NginxSuite", Ordered, ContinueOnFailure, func() {
AfterEach(func() {
s.TearDownTest()
})
for _, test := range nginxTests {
for filename, tests := range nginxTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})
var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
@ -119,14 +122,16 @@ var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
s.TearDownTest()
})
for _, test := range nginxSoloTests {
for filename, tests := range nginxSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})

View File

@ -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,16 +68,18 @@ var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() {
s.TearDownTest()
})
for _, test := range noTopoTests {
for filename, tests := range noTopoTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})
var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
@ -95,14 +97,16 @@ var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
s.TearDownTest()
})
for _, test := range noTopoSoloTests {
for filename, tests := range noTopoSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})

View File

@ -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,16 +77,18 @@ var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() {
s.TearDownTest()
})
for _, test := range nsTests {
for filename, tests := range nsTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})
var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
@ -104,14 +106,16 @@ var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
s.TearDownTest()
})
for _, test := range nsSoloTests {
for filename, tests := range nsSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})

View File

@ -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,16 +44,18 @@ var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() {
s.TearDownTest()
})
for _, test := range tapTests {
for filename, tests := range tapTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})
var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
@ -71,14 +73,16 @@ var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
s.TearDownTest()
})
for _, test := range tapSoloTests {
for filename, tests := range tapSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})

View File

@ -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,16 +101,18 @@ var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() {
})
// https://onsi.github.io/ginkgo/#dynamically-generating-specs
for _, test := range vethTests {
for filename, tests := range vethTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})
var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
@ -129,14 +131,16 @@ var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
})
// https://onsi.github.io/ginkgo/#dynamically-generating-specs
for _, test := range vethSoloTests {
for filename, tests := range vethSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := strings.Split(funcValue.Name(), ".")[2]
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(suiteTimeout))
}
}
})