From b4531067770645bfeb64fa88a8ced449313597af Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 3 Nov 2019 15:20:53 -0500 Subject: [PATCH] test: Exit early during resource helper test The test will panic if it fails, and should instead check and exit when invalid conditions are hit. --- .../k8s.io/cli-runtime/pkg/resource/helper_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/staging/src/k8s.io/cli-runtime/pkg/resource/helper_test.go b/staging/src/k8s.io/cli-runtime/pkg/resource/helper_test.go index a94f7395d05..3514b759bd9 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/resource/helper_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/resource/helper_test.go @@ -592,7 +592,7 @@ func TestHelperReplace(t *testing.T) { Req: expectPut, }, } - for i, tt := range tests { + for _, tt := range tests { t.Run(tt.Name, func(t *testing.T) { client := &fake.RESTClient{ GroupVersion: corev1GV, @@ -607,24 +607,24 @@ func TestHelperReplace(t *testing.T) { } _, err := modifier.Replace(tt.Namespace, "foo", tt.Overwrite, tt.Object) if (err != nil) != tt.Err { - t.Errorf("%d: unexpected error: %t %v", i, tt.Err, err) + t.Fatalf("unexpected error: %t %v", tt.Err, err) } if err != nil { return } - if tt.Req != nil && !tt.Req(tt.ExpectPath, client.Req) { - t.Errorf("%d: unexpected request: %#v", i, client.Req) + if tt.Req != nil && (client.Req == nil || !tt.Req(tt.ExpectPath, client.Req)) { + t.Fatalf("unexpected request: %#v", client.Req) } body, err := ioutil.ReadAll(client.Req.Body) if err != nil { - t.Fatalf("%d: unexpected error: %#v", i, err) + t.Fatalf("unexpected error: %#v", err) } expect := []byte{} if tt.ExpectObject != nil { expect = []byte(runtime.EncodeOrDie(corev1Codec, tt.ExpectObject)) } if !reflect.DeepEqual(expect, body) { - t.Errorf("%d: unexpected body: %s", i, string(body)) + t.Fatalf("unexpected body: %s", string(body)) } }) }