Simplify package skipping test

This commit is contained in:
Jordan Liggitt 2019-02-28 12:40:28 -05:00
parent 23a41c9d7e
commit 1676a49d8c

View File

@ -16,7 +16,10 @@ limitations under the License.
package naming package naming
import "testing" import (
"strings"
"testing"
)
func TestGetNameFromCallsite(t *testing.T) { func TestGetNameFromCallsite(t *testing.T) {
tests := []struct { tests := []struct {
@ -26,17 +29,17 @@ func TestGetNameFromCallsite(t *testing.T) {
}{ }{
{ {
name: "simple", name: "simple",
expected: "k8s.io/apimachinery/pkg/util/naming/from_stack_test.go:50", expected: "k8s.io/apimachinery/pkg/util/naming/from_stack_test.go:",
}, },
{ {
name: "ignore-package", name: "ignore-package",
ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming"}, ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming"},
expected: "testing/testing.go:827", expected: "testing/testing.go:",
}, },
{ {
name: "ignore-file", name: "ignore-file",
ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming/from_stack_test.go"}, ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming/from_stack_test.go"},
expected: "testing/testing.go:827", expected: "testing/testing.go:",
}, },
{ {
name: "ignore-multiple", name: "ignore-multiple",
@ -48,8 +51,8 @@ func TestGetNameFromCallsite(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
actual := GetNameFromCallsite(tc.ignoredPackages...) actual := GetNameFromCallsite(tc.ignoredPackages...)
if tc.expected != actual { if !strings.HasPrefix(actual, tc.expected) {
t.Fatalf("expected %q, got %q", tc.expected, actual) t.Fatalf("expected string with prefix %q, got %q", tc.expected, actual)
} }
}) })
} }