mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
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.
This commit is contained in:
parent
8a9b8c87c4
commit
b453106777
@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user