From 851c120a74af76fa7c6c0676945736be0f8a62d8 Mon Sep 17 00:00:00 2001 From: Ross Bryan Date: Tue, 27 Feb 2024 21:34:38 -0500 Subject: [PATCH] chore: upgrade go.mod to 1.20 (matches Dockerfile builder) + ioutil deprecation Topic: 1.20 Relative: rm-reflection Signed-off-by: Ross Bryan --- go.mod | 2 +- pkg/client/quay/client.go | 3 +-- pkg/client/quay/client_test.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 pkg/client/quay/client_test.go diff --git a/go.mod b/go.mod index a9f6fe94..4588ea4e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/quay/quay-bridge-operator -go 1.17 +go 1.20 require ( github.com/go-logr/logr v1.2.4 diff --git a/pkg/client/quay/client.go b/pkg/client/quay/client.go index f638e974..2e26eb40 100644 --- a/pkg/client/quay/client.go +++ b/pkg/client/quay/client.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" ) @@ -195,7 +194,7 @@ func (c *QuayClient) do(req *http.Request, v interface{}) (*http.Response, error if v != nil { if _, ok := v.(*StringValue); ok { - responseData, err := ioutil.ReadAll(resp.Body) + responseData, err := io.ReadAll(resp.Body) if err != nil { return resp, err } diff --git a/pkg/client/quay/client_test.go b/pkg/client/quay/client_test.go new file mode 100644 index 00000000..0387550b --- /dev/null +++ b/pkg/client/quay/client_test.go @@ -0,0 +1,30 @@ +package quay_test + +import ( + "net/http" + "testing" +) + +func TestGetUser(t *testing.T) { + // Create a new instance of the mock controller + ctrl := quay.NewController(t) + defer ctrl.Finish() + + // Create a mock instance of QuayClient + mockQuayClient := mock_quay.NewMockQuayClient(ctrl) + + // Prepare expected user and response + expectedUser := quay.User{} // Define your expected User struct here + mockResponse := &http.Response{} // Mock HTTP response + + // Set up expectations + mockQuayClient.EXPECT().GetUser().Return(expectedUser, mockResponse, nil) + + // Call the method under test + user, resp, err := mockQuayClient.GetUser() + + // Assert the results + assert.NoError(t, err) + assert.Equal(t, expectedUser, user) + assert.Equal(t, mockResponse, resp) +}