From 9445a839c89f7a12336161c018a6d020b983840c Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Wed, 13 Mar 2024 13:34:58 -0400 Subject: [PATCH] refactor out 'io/ioutil' (#224) Signed-off-by: Michael Valdron --- .../github.com/hashicorp/hcl/.gitignore | 18 +-- index/server/pkg/server/endpoint.go | 32 ++-- index/server/pkg/server/endpoint_test.go | 139 +++++++++--------- index/server/pkg/server/index.go | 3 +- index/server/pkg/server/registry.go | 3 +- index/server/pkg/util/util.go | 15 +- index/server/pkg/util/util_test.go | 5 +- .../pkg/tests/indexserver_tests.go | 16 +- .../pkg/tests/ociregistry_tests.go | 4 +- tests/integration/pkg/util/util.go | 4 +- 10 files changed, 121 insertions(+), 118 deletions(-) diff --git a/index/generator/vendor/github.com/hashicorp/hcl/.gitignore b/index/generator/vendor/github.com/hashicorp/hcl/.gitignore index 15586a2b5..822fa09f5 100644 --- a/index/generator/vendor/github.com/hashicorp/hcl/.gitignore +++ b/index/generator/vendor/github.com/hashicorp/hcl/.gitignore @@ -1,9 +1,9 @@ -y.output - -# ignore intellij files -.idea -*.iml -*.ipr -*.iws - -*.test +y.output + +# ignore intellij files +.idea +*.iml +*.ipr +*.iws + +*.test diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index ea15cc006..3aa9a7464 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -18,7 +18,6 @@ package server import ( "encoding/json" "fmt" - "io/ioutil" "log" "net/http" "net/http/httputil" @@ -121,15 +120,15 @@ func (*Server) ServeDevfileIndexV1WithType(c *gin.Context, indexType string, par buildIndexAPIResponse(c, indexType, true, IndexParams(params)) } -func (*Server) PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams){ +func (*Server) PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams){ +func (*Server) PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams){ +func (*Server) DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams) { SetMethodNotAllowedJSONResponse(c) } @@ -157,14 +156,17 @@ func (*Server) ServeHealthCheck(c *gin.Context) { Message: "the server is up and running", }) } + // PostHealthCheck serves endpoint `/health` for registry health check with POST request func (*Server) PostHealthCheck(c *gin.Context) { SetMethodNotAllowedJSONResponse(c) } + // PutHealthCheck serves endpoint `/health` for registry health check with PUT request func (*Server) PutHealthCheck(c *gin.Context) { SetMethodNotAllowedJSONResponse(c) } + // DeleteHealthCheck serves endpoint `/health` for registry health check with DELETE request func (*Server) DeleteHealthCheck(c *gin.Context) { SetMethodNotAllowedJSONResponse(c) @@ -198,15 +200,15 @@ func (*Server) ServeDevfileWithVersion(c *gin.Context, name string, version stri } } -func (*Server) PostDevfileWithVersion(c *gin.Context, name string, version string){ +func (*Server) PostDevfileWithVersion(c *gin.Context, name string, version string) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) PutDevfileWithVersion(c *gin.Context, name string, version string){ +func (*Server) PutDevfileWithVersion(c *gin.Context, name string, version string) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) DeleteDevfileWithVersion(c *gin.Context, name string, version string){ +func (*Server) DeleteDevfileWithVersion(c *gin.Context, name string, version string) { SetMethodNotAllowedJSONResponse(c) } @@ -378,7 +380,7 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string localLoc = downloadFilePath } - downloadBytes, err = ioutil.ReadFile(filepath.Clean(localLoc)) + downloadBytes, err = os.ReadFile(filepath.Clean(localLoc)) if err != nil { log.Print(err.Error()) c.JSON(http.StatusInternalServerError, gin.H{ @@ -431,15 +433,15 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string } } -func (*Server) PostDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ +func (*Server) PostDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) PutDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ +func (*Server) PutDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) { SetMethodNotAllowedJSONResponse(c) } -func (*Server) DeleteDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ +func (*Server) DeleteDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) { SetMethodNotAllowedJSONResponse(c) } @@ -634,7 +636,7 @@ func buildProxyErrorResponse(w http.ResponseWriter, r *http.Request, err error, // schema from `indexPath` given by server. func fetchDevfile(c *gin.Context, name string, version string) ([]byte, indexSchema.Schema) { var index []indexSchema.Schema - bytes, err := ioutil.ReadFile(indexPath) + bytes, err := os.ReadFile(indexPath) if err != nil { log.Print(err.Error()) c.JSON(http.StatusInternalServerError, gin.H{ @@ -730,7 +732,7 @@ func fetchDevfile(c *gin.Context, name string, version string) ([]byte, indexSch if sampleDevfilePath != "" { if _, err = os.Stat(sampleDevfilePath); err == nil { /* #nosec G304 -- sampleDevfilePath is constructed from path.Join which cleans the input paths */ - bytes, err = ioutil.ReadFile(sampleDevfilePath) + bytes, err = os.ReadFile(sampleDevfilePath) } if err != nil { log.Print(err.Error()) @@ -803,8 +805,8 @@ func ServeOciProxy(c *gin.Context) { proxy.ServeHTTP(c.Writer, c.Request) } -func SetMethodNotAllowedJSONResponse(c *gin.Context){ +func SetMethodNotAllowedJSONResponse(c *gin.Context) { c.JSON(http.StatusMethodNotAllowed, MethodNotAllowedResponse{ Message: "Only GET requests are supported.", }) -} \ No newline at end of file +} diff --git a/index/server/pkg/server/endpoint_test.go b/index/server/pkg/server/endpoint_test.go index 2fd581d08..ab083a09c 100644 --- a/index/server/pkg/server/endpoint_test.go +++ b/index/server/pkg/server/endpoint_test.go @@ -22,7 +22,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "log" "net/http" "net/http/httptest" @@ -387,7 +386,7 @@ func TestServeHealthCheck(t *testing.T) { return } - bytes, err := ioutil.ReadAll(w.Body) + bytes, err := io.ReadAll(w.Body) if err != nil { t.Fatalf("Did not expect error: %v", err) return @@ -1217,22 +1216,22 @@ func TestRootEndpointMethodNotAllowed(t *testing.T) { wantCode int }{ { - name: "POST / - Successful Response Test", - handler: server.PostRootEndpoint, + name: "POST / - Successful Response Test", + handler: server.PostRootEndpoint, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT / - Successful Response Test", - handler: server.PutRootEndpoint, + name: "PUT / - Successful Response Test", + handler: server.PutRootEndpoint, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE / - Successful Response Test", - handler: server.DeleteRootEndpoint, + name: "DELETE / - Successful Response Test", + handler: server.DeleteRootEndpoint, wantCode: http.StatusMethodNotAllowed, }, } - + for _, test := range tests { t.Run(test.name, func(tt *testing.T) { gin.SetMode(gin.TestMode) @@ -1261,22 +1260,22 @@ func TestHealthCheckMethodNotAllowed(t *testing.T) { wantCode int }{ { - name: "POST /health - Successful Response Test", - handler: server.PostHealthCheck, + name: "POST /health - Successful Response Test", + handler: server.PostHealthCheck, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /health - Successful Response Test", - handler: server.PutHealthCheck, + name: "PUT /health - Successful Response Test", + handler: server.PutHealthCheck, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /health - Successful Response Test", - handler: server.DeleteHealthCheck, + name: "DELETE /health - Successful Response Test", + handler: server.DeleteHealthCheck, wantCode: http.StatusMethodNotAllowed, }, } - + for _, test := range tests { t.Run(test.name, func(tt *testing.T) { gin.SetMode(gin.TestMode) @@ -1305,37 +1304,41 @@ func TestDevfileIndexV1MethodNotAllowed(t *testing.T) { wantCode int }{ { - name: "POST /index - Successful Response Test", - handler: server.PostDevfileIndexV1, + name: "POST /index - Successful Response Test", + handler: server.PostDevfileIndexV1, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /index - Successful Response Test", - handler: server.PutDevfileIndexV1, + name: "PUT /index - Successful Response Test", + handler: server.PutDevfileIndexV1, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /index - Successful Response Test", - handler: server.DeleteDevfileIndexV1, + name: "DELETE /index - Successful Response Test", + handler: server.DeleteDevfileIndexV1, wantCode: http.StatusMethodNotAllowed, }, { name: "POST /index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfileIndexV1WithType(c, "stack", PostDevfileIndexV1WithTypeParams{})}, + handler: func(c *gin.Context) { + server.PostDevfileIndexV1WithType(c, "stack", PostDevfileIndexV1WithTypeParams{}) + }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfileIndexV1WithType(c, "stack", PutDevfileIndexV1WithTypeParams{})}, + name: "PUT /index/{indexType} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfileIndexV1WithType(c, "stack", PutDevfileIndexV1WithTypeParams{}) }, wantCode: http.StatusMethodNotAllowed, }, { name: "DELETE /index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfileIndexV1WithType(c, "stack", DeleteDevfileIndexV1WithTypeParams{})}, + handler: func(c *gin.Context) { + server.DeleteDevfileIndexV1WithType(c, "stack", DeleteDevfileIndexV1WithTypeParams{}) + }, wantCode: http.StatusMethodNotAllowed, }, } - + for _, test := range tests { t.Run(test.name, func(tt *testing.T) { gin.SetMode(gin.TestMode) @@ -1364,37 +1367,41 @@ func TestDevfileIndexV2MethodNotAllowed(t *testing.T) { wantCode int }{ { - name: "POST /v2index - Successful Response Test", - handler: server.PostDevfileIndexV2, + name: "POST /v2index - Successful Response Test", + handler: server.PostDevfileIndexV2, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /v2index - Successful Response Test", - handler: server.PutDevfileIndexV2, + name: "PUT /v2index - Successful Response Test", + handler: server.PutDevfileIndexV2, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /v2index - Successful Response Test", - handler: server.DeleteDevfileIndexV2, + name: "DELETE /v2index - Successful Response Test", + handler: server.DeleteDevfileIndexV2, wantCode: http.StatusMethodNotAllowed, }, { name: "POST /v2index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfileIndexV2WithType(c, "stack", PostDevfileIndexV2WithTypeParams{})}, + handler: func(c *gin.Context) { + server.PostDevfileIndexV2WithType(c, "stack", PostDevfileIndexV2WithTypeParams{}) + }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /v2index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfileIndexV2WithType(c, "stack", PutDevfileIndexV2WithTypeParams{})}, + name: "PUT /v2index/{indexType} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfileIndexV2WithType(c, "stack", PutDevfileIndexV2WithTypeParams{}) }, wantCode: http.StatusMethodNotAllowed, }, { name: "DELETE /v2index/{indexType} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfileIndexV2WithType(c, "stack", DeleteDevfileIndexV2WithTypeParams{})}, + handler: func(c *gin.Context) { + server.DeleteDevfileIndexV2WithType(c, "stack", DeleteDevfileIndexV2WithTypeParams{}) + }, wantCode: http.StatusMethodNotAllowed, }, } - + for _, test := range tests { t.Run(test.name, func(tt *testing.T) { gin.SetMode(gin.TestMode) @@ -1418,72 +1425,72 @@ func TestDevfileMethodNotAllowed(t *testing.T) { setupVars() server := &Server{} tests := []struct { - name string - handler gin.HandlerFunc - wantCode int + name string + handler gin.HandlerFunc + wantCode int }{ { - name: "POST /devfiles/{stack} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfile(c, "go")}, + name: "POST /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context) { server.PostDevfile(c, "go") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /devfiles/{stack} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfile(c, "go")}, + name: "PUT /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfile(c, "go") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /devfiles/{stack} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfile(c, "go")}, + name: "DELETE /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context) { server.DeleteDevfile(c, "go") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "POST /devfiles/{stack}/{version} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfileWithVersion(c, "go", "2.0.0")}, + name: "POST /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context) { server.PostDevfileWithVersion(c, "go", "2.0.0") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /devfiles/{stack}/{version} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfileWithVersion(c, "go", "2.0.0")}, + name: "PUT /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfileWithVersion(c, "go", "2.0.0") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /devfiles/{stack}/{version} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfileWithVersion(c, "go", "2.0.0")}, + name: "DELETE /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context) { server.DeleteDevfileWithVersion(c, "go", "2.0.0") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "POST /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfileStarterProject(c, "go", "go-starter")}, + name: "POST /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.PostDevfileStarterProject(c, "go", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfileStarterProject(c, "go", "go-starter")}, + name: "PUT /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfileStarterProject(c, "go", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfileStarterProject(c, "go", "go-starter")}, + name: "DELETE /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.DeleteDevfileStarterProject(c, "go", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "POST /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.PostDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + name: "POST /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.PostDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "PUT /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.PutDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + name: "PUT /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.PutDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, { - name: "DELETE /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", - handler: func(c *gin.Context){server.DeleteDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + name: "DELETE /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context) { server.DeleteDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter") }, wantCode: http.StatusMethodNotAllowed, }, } - + for _, test := range tests { t.Run(test.name, func(tt *testing.T) { gin.SetMode(gin.TestMode) diff --git a/index/server/pkg/server/index.go b/index/server/pkg/server/index.go index 3caab2141..66bfda560 100644 --- a/index/server/pkg/server/index.go +++ b/index/server/pkg/server/index.go @@ -18,7 +18,6 @@ package server import ( "crypto/tls" "encoding/json" - "io/ioutil" "log" "net/http" "os" @@ -116,7 +115,7 @@ func ServeRegistry() { } // Load index file - bytes, err := ioutil.ReadFile(indexPath) + bytes, err := os.ReadFile(indexPath) if err != nil { log.Fatalf("failed to read index file: %s", err.Error()) } diff --git a/index/server/pkg/server/registry.go b/index/server/pkg/server/registry.go index 3958229f3..7e29c9d76 100644 --- a/index/server/pkg/server/registry.go +++ b/index/server/pkg/server/registry.go @@ -19,7 +19,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "log" "os" "path" @@ -72,7 +71,7 @@ func pushStackToRegistry(versionComponent indexSchema.Version, stackName string) resourcePath = filepath.Join(stacksPath, stackName, resource) } /* #nosec G304 -- resourcePath is constructed from filepath.Join which cleans the input paths */ - resourceContent, err := ioutil.ReadFile(resourcePath) + resourceContent, err := os.ReadFile(resourcePath) if err != nil { return err } diff --git a/index/server/pkg/util/util.go b/index/server/pkg/util/util.go index a479c8b02..2e1145eee 100644 --- a/index/server/pkg/util/util.go +++ b/index/server/pkg/util/util.go @@ -18,7 +18,7 @@ package util import ( "encoding/base64" "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -46,7 +46,7 @@ func IsHtmlRequested(acceptHeader []string) bool { func EncodeIndexIconToBase64(indexPath string, base64IndexPath string) ([]byte, error) { // load index /* #nosec G304 -- indexPath is derived from known paths set in the docker image */ - bytes, err := ioutil.ReadFile(indexPath) + bytes, err := os.ReadFile(indexPath) if err != nil { return nil, err } @@ -94,13 +94,13 @@ func encodeToBase64(uri string) (string, error) { } defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) if err != nil { return "", err } } else { /* #nosec G304 -- uri is derived from known paths set in the docker image */ - bytes, err = ioutil.ReadFile(uri) + bytes, err = os.ReadFile(uri) if err != nil { return "", err } @@ -125,7 +125,7 @@ func encodeToBase64(uri string) (string, error) { func ReadIndexPath(indexPath string) ([]indexSchema.Schema, error) { // load index /* #nosec G304 -- not user input */ - bytes, err := ioutil.ReadFile(indexPath) + bytes, err := os.ReadFile(indexPath) if err != nil { return nil, err } @@ -198,10 +198,7 @@ func ConvertToOldIndexFormat(schemaList []indexSchema.Schema) []indexSchema.Sche } func IsTelemetryEnabled() bool { - if len(telemetryKey) > 0 { - return true - } - return false + return len(telemetryKey) > 0 } // IsEnabled return value of a boolean environment variable, if environment variable diff --git a/index/server/pkg/util/util_test.go b/index/server/pkg/util/util_test.go index e6cdede97..6861b08de 100644 --- a/index/server/pkg/util/util_test.go +++ b/index/server/pkg/util/util_test.go @@ -18,7 +18,6 @@ package util import ( "encoding/json" "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -215,11 +214,11 @@ func TestGetOptionalEnv(t *testing.T) { func TestConvertToOldIndexFormat(t *testing.T) { const inputIndexFilePath = "../../tests/resources/newIndexStruct.json" const wantIndexFilePath = "../../tests/resources/oldIndexStruct.json" - bytes, err := ioutil.ReadFile(inputIndexFilePath) + bytes, err := os.ReadFile(inputIndexFilePath) if err != nil { t.Errorf("Failed to read newIndexStruct.json: %v", err) } - expected, err := ioutil.ReadFile(wantIndexFilePath) + expected, err := os.ReadFile(wantIndexFilePath) if err != nil { t.Errorf("Failed to oldIndexStruct.json: %v", err) } diff --git a/tests/integration/pkg/tests/indexserver_tests.go b/tests/integration/pkg/tests/indexserver_tests.go index 2b1842ebd..207b6efe5 100644 --- a/tests/integration/pkg/tests/indexserver_tests.go +++ b/tests/integration/pkg/tests/indexserver_tests.go @@ -16,7 +16,7 @@ package tests import ( - "io/ioutil" + "io" "net/http" devfilePkg "github.com/devfile/library/v2/pkg/devfile" @@ -50,7 +50,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { // Check the path of the response. Should have been redirected to /viewer gomega.Expect(resp.Request.URL.Path).To(gomega.Equal("/viewer")) - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) body := string(bytes) gomega.Expect(body).To(gomega.ContainSubstring("")) @@ -66,7 +66,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { // Check the path of the response. Should have been redirected to /viewer gomega.Expect(resp.Request.URL.Path).To(gomega.Equal("/viewer")) - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) body := string(bytes) @@ -311,7 +311,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusAccepted)) @@ -328,7 +328,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusAccepted)) @@ -346,7 +346,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusAccepted)) @@ -368,7 +368,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusAccepted)) @@ -390,7 +390,7 @@ var _ = ginkgo.Describe("[Verify index server is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bytes, err = ioutil.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusAccepted)) diff --git a/tests/integration/pkg/tests/ociregistry_tests.go b/tests/integration/pkg/tests/ociregistry_tests.go index cbba212c4..f26df097c 100644 --- a/tests/integration/pkg/tests/ociregistry_tests.go +++ b/tests/integration/pkg/tests/ociregistry_tests.go @@ -18,7 +18,7 @@ package tests import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/http" "github.com/devfile/registry-support/tests/integration/pkg/config" @@ -42,7 +42,7 @@ var _ = ginkgo.Describe("[Verify oci registry is working properly]", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) // Parse the oci catalog entries and verify it has at least 1 entry in it diff --git a/tests/integration/pkg/util/util.go b/tests/integration/pkg/util/util.go index a16dd6c0b..ee788f8ca 100644 --- a/tests/integration/pkg/util/util.go +++ b/tests/integration/pkg/util/util.go @@ -18,7 +18,7 @@ package util import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "time" @@ -70,7 +70,7 @@ func GetRegistryIndex(url string) []indexSchema.Schema { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) gomega.Expect(err).NotTo(gomega.HaveOccurred()) var registryIndex []indexSchema.Schema