integration: detect test names with reflect

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2017-11-29 18:49:04 -08:00
parent f343fc30ec
commit e3f85cc1ac
3 changed files with 19 additions and 14 deletions

View File

@ -10,13 +10,11 @@ import (
"github.com/stretchr/testify/assert"
)
var testCases = map[string]integration.Test{
"TestCallDiskUsage": testCallDiskUsage,
"TestBuildMultiMount": testBuildMultiMount,
}
func TestClientIntegration(t *testing.T) {
integration.Run(t, testCases)
integration.Run(t, []integration.Test{
testCallDiskUsage,
testBuildMultiMount,
})
}
func testCallDiskUsage(t *testing.T, sb integration.Sandbox) {

View File

@ -6,10 +6,8 @@ import (
"github.com/moby/buildkit/util/testutil/integration"
)
var testCases = map[string]integration.Test{
"TestDiskUsage": testDiskUsage,
}
func TestCLIIntegration(t *testing.T) {
integration.Run(t, testCases)
integration.Run(t, []integration.Test{
testDiskUsage,
})
}

View File

@ -2,6 +2,9 @@ package integration
import (
"os/exec"
"reflect"
"runtime"
"strings"
"testing"
"github.com/pkg/errors"
@ -32,13 +35,13 @@ func List() []Worker {
return defaultWorkers
}
func Run(t *testing.T, testCases map[string]Test) {
func Run(t *testing.T, testCases []Test) {
if testing.Short() {
t.Skip("skipping in short mode")
}
for _, br := range List() {
for name, tc := range testCases {
ok := t.Run(name+"/worker="+br.Name(), func(t *testing.T) {
for _, tc := range testCases {
ok := t.Run(getFunctionName(tc)+"/worker="+br.Name(), func(t *testing.T) {
sb, close, err := br.New()
if err != nil {
if errors.Cause(err) == ErrorRequirements {
@ -58,3 +61,9 @@ func Run(t *testing.T, testCases map[string]Test) {
}
}
}
func getFunctionName(i interface{}) string {
fullname := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
dot := strings.LastIndex(fullname, ".") + 1
return strings.Title(fullname[dot:])
}