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>
diff --git a/extras/hs-test/README.rst b/extras/hs-test/README.rst
index 1dc1039..a88251a 100644
--- a/extras/hs-test/README.rst
+++ b/extras/hs-test/README.rst
@@ -89,6 +89,30 @@
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 8cbf936..8d7e2ed 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 @@
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 4c6e9db..7caf16e 100644
--- a/extras/hs-test/suite_nginx_test.go
+++ b/extras/hs-test/suite_nginx_test.go
@@ -17,18 +17,18 @@
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 @@
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 @@
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 260fc1d..af0cf9a 100644
--- a/extras/hs-test/suite_no_topo_test.go
+++ b/extras/hs-test/suite_no_topo_test.go
@@ -14,18 +14,18 @@
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 @@
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 @@
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 7bdb90b..b4fa771 100644
--- a/extras/hs-test/suite_ns_test.go
+++ b/extras/hs-test/suite_ns_test.go
@@ -15,18 +15,18 @@
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 @@
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 @@
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 cb06533..bb7082d 100644
--- a/extras/hs-test/suite_tap_test.go
+++ b/extras/hs-test/suite_tap_test.go
@@ -13,14 +13,14 @@
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 @@
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 @@
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 13ef5ef..49a36ca 100644
--- a/extras/hs-test/suite_veth_test.go
+++ b/extras/hs-test/suite_veth_test.go
@@ -16,18 +16,18 @@
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 @@
})
// 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 @@
})
// 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))
+ }
}
})