• k8s-merge-robot's avatar
    Merge pull request #26942 from xiangpengzhao/fix_testcase · 5a7b52b8
    k8s-merge-robot authored
    Automatic merge from submit-queue
    
    Fix panic in schema test
    
    If the swagger files for testing are lost, the func `loadSchemaForTest` or `NewSwaggerSchemaFromBytes` will return a non-nil error and a nil schema. In this case, the calling for `ValidateBytes` will result in panic. So, call Fatalf instead of Errorf.
    
    Also fix minor typos.
    
    Test logs:
    
    ```
    --- FAIL: TestLoad (0.01s)
    	schema_test.go:131: Failed to load: open ../../../api/swagger-spec/v1.json: no such file or directory
    --- FAIL: TestValidateOk (0.00s)
    	schema_test.go:138: Failed to load: open ../../../api/swagger-spec/v1.json: no such file or directory
    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    	panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x20 pc=0x4d52df]
    
    goroutine 10 [running]:
    panic(0x15fffa0, 0xc8200100a0)
    	/usr/local/go/src/runtime/panic.go:481 +0x3e6
    testing.tRunner.func1(0xc820085a70)
    	/usr/local/go/src/testing/testing.go:467 +0x192
    panic(0x15fffa0, 0xc8200100a0)
    	/usr/local/go/src/runtime/panic.go:443 +0x4e9
    k8s.io/kubernetes/pkg/api/validation.TestValidateOk(0xc820085a70)
    	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/api/validation/schema_test.go:159 +0x79f
    testing.tRunner(0xc820085a70, 0x22aad68)
    	/usr/local/go/src/testing/testing.go:473 +0x98
    created by testing.RunTests
    	/usr/local/go/src/testing/testing.go:582 +0x892
    FAIL	k8s.io/kubernetes/pkg/api/validation	0.048s
    ```
    5a7b52b8
Name
Last commit
Last update
..
testdata/v1 Loading commit data...
doc.go Loading commit data...
events.go Loading commit data...
events_test.go Loading commit data...
name.go Loading commit data...
name_test.go Loading commit data...
schema.go Loading commit data...
schema_test.go Loading commit data...
validation.go Loading commit data...
validation_test.go Loading commit data...