Call Fatalf instead of Errorf when loading schema returns error

This commit is contained in:
xiangpengzhao 2016-06-07 03:35:45 -04:00
parent 812b87c8e6
commit a1b535f918

View File

@ -135,7 +135,7 @@ func TestLoad(t *testing.T) {
func TestValidateOk(t *testing.T) { func TestValidateOk(t *testing.T) {
schema, err := loadSchemaForTest() schema, err := loadSchemaForTest()
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Fatalf("Failed to load: %v", err)
} }
tests := []struct { tests := []struct {
obj runtime.Object obj runtime.Object
@ -167,7 +167,7 @@ func TestValidateOk(t *testing.T) {
func TestValidateDifferentApiVersions(t *testing.T) { func TestValidateDifferentApiVersions(t *testing.T) {
schema, err := loadSchemaForTest() schema, err := loadSchemaForTest()
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Fatalf("Failed to load: %v", err)
} }
pod := &api.Pod{} pod := &api.Pod{}
@ -203,7 +203,7 @@ func TestValidateDifferentApiVersions(t *testing.T) {
func TestInvalid(t *testing.T) { func TestInvalid(t *testing.T) {
schema, err := loadSchemaForTest() schema, err := loadSchemaForTest()
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Fatalf("Failed to load: %v", err)
} }
tests := []string{ tests := []string{
"invalidPod1.json", // command is a string, instead of []string. "invalidPod1.json", // command is a string, instead of []string.
@ -227,7 +227,7 @@ func TestInvalid(t *testing.T) {
func TestValid(t *testing.T) { func TestValid(t *testing.T) {
schema, err := loadSchemaForTest() schema, err := loadSchemaForTest()
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Fatalf("Failed to load: %v", err)
} }
tests := []string{ tests := []string{
"validPod.yaml", "validPod.yaml",
@ -239,7 +239,7 @@ func TestValid(t *testing.T) {
} }
err = schema.ValidateBytes(pod) err = schema.ValidateBytes(pod)
if err != nil { if err != nil {
t.Errorf("unexpected error %s, for pod %s", err, pod) t.Errorf("unexpected error: %s, for pod %s", err, pod)
} }
} }
} }
@ -274,7 +274,7 @@ func TestVersionRegex(t *testing.T) {
// Tests that validation works fine when spec contains "type": "any" instead of "type": "object" // Tests that validation works fine when spec contains "type": "any" instead of "type": "object"
// Ref: https://github.com/kubernetes/kubernetes/issues/24309 // Ref: https://github.com/kubernetes/kubernetes/issues/24309
func TestTypeOAny(t *testing.T) { func TestTypeAny(t *testing.T) {
data, err := readSwaggerFile() data, err := readSwaggerFile()
if err != nil { if err != nil {
t.Errorf("failed to read swagger file: %v", err) t.Errorf("failed to read swagger file: %v", err)
@ -283,7 +283,7 @@ func TestTypeOAny(t *testing.T) {
newData := strings.Replace(string(data), `"type": "object"`, `"type": "any"`, -1) newData := strings.Replace(string(data), `"type": "object"`, `"type": "any"`, -1)
schema, err := NewSwaggerSchemaFromBytes([]byte(newData), nil) schema, err := NewSwaggerSchemaFromBytes([]byte(newData), nil)
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Fatalf("Failed to load: %v", err)
} }
tests := []string{ tests := []string{
"validPod.yaml", "validPod.yaml",
@ -304,7 +304,7 @@ func TestTypeOAny(t *testing.T) {
} }
err = schema.ValidateBytes(podBytes) err = schema.ValidateBytes(podBytes)
if err != nil { if err != nil {
t.Errorf("unexpected error %s, for pod %s", err, string(podBytes)) t.Errorf("unexpected error: %s, for pod %s", err, string(podBytes))
} }
} }
} }