mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add unit tests for checkResponseForErrors()
This commit is contained in:
parent
7fb7710c55
commit
1c3a1c665e
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -183,3 +184,50 @@ func Test_portainerClientImp_do(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkResponseForErrors(t *testing.T) {
|
||||
type args struct {
|
||||
resp *http.Response
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "generic error",
|
||||
args: args{
|
||||
resp: func() (resp *http.Response) {
|
||||
resp = &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
}
|
||||
bodyBytes, _ := json.Marshal(map[string]interface{}{
|
||||
"Err": "Error",
|
||||
"Details": "Not found",
|
||||
})
|
||||
resp.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes))
|
||||
return
|
||||
}(),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "non generic error",
|
||||
args: args{
|
||||
resp: func() (resp *http.Response) {
|
||||
resp = &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("Err"))),
|
||||
}
|
||||
return
|
||||
}(),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.wantErr, checkResponseForErrors(tt.args.resp) != nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user