Skip to content

Commit

Permalink
Update updater_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
house-lee committed Jun 12, 2024
1 parent ddd6ef7 commit dc37bb8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/metadata/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func Test_agentInfoUpdaterImpl_Update(t *testing.T) {
}
tests := []struct {
name string
expectations func(client *MockhttpClient)
expectations func(client *MockhttpClient, respBody *MockReadCloser)
wantErr bool
}{
{
"successful response",
func(client *MockhttpClient) {
func(client *MockhttpClient, respBody *MockReadCloser) {
reqMatcher := &mockutils.HTTPRequestMatcher{
ExpectedRequest: newRequest(t, []byte("{\"dotty_status\":\"running\",\"ssh_info\":{\"port\":256}}")),
}
Expand All @@ -40,18 +40,19 @@ func Test_agentInfoUpdaterImpl_Update(t *testing.T) {
},
{
"unsuccessful response code",
func(client *MockhttpClient) {
func(client *MockhttpClient, respBody *MockReadCloser) {
reqMatcher := &mockutils.HTTPRequestMatcher{
ExpectedRequest: newRequest(t, []byte("{\"dotty_status\":\"running\",\"ssh_info\":{\"port\":256}}")),
}

client.EXPECT().Do(reqMatcher).Return(&http.Response{StatusCode: 404}, nil)
client.EXPECT().Do(reqMatcher).Return(&http.Response{StatusCode: 404, Body: respBody}, nil)
respBody.EXPECT().Close()
},
true,
},
{
"error from http client",
func(client *MockhttpClient) {
func(client *MockhttpClient, respBody *MockReadCloser) {
reqMatcher := &mockutils.HTTPRequestMatcher{
ExpectedRequest: newRequest(t, []byte("{\"dotty_status\":\"running\",\"ssh_info\":{\"port\":256}}")),
}
Expand All @@ -65,7 +66,8 @@ func Test_agentInfoUpdaterImpl_Update(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockhttpClient(ctrl)
tt.expectations(client)
readCloser := NewMockReadCloser(ctrl)
tt.expectations(client, readCloser)
m := &agentInfoUpdaterImpl{
client: client,
}
Expand Down

0 comments on commit dc37bb8

Please sign in to comment.