diff --git a/pkg/api/authn_test.go b/pkg/api/authn_test.go index c0bfcef89..570f6db8f 100644 --- a/pkg/api/authn_test.go +++ b/pkg/api/authn_test.go @@ -70,7 +70,7 @@ func TestAllowedMethodsHeaderAPIKey(t *testing.T) { ctrlManager.StartAndWait(port) defer ctrlManager.StopServer() - resp, _ := resty.R().Options(baseURL + constants.APIKeyPath) + resp, _ := resty.New().R().Options(baseURL + constants.APIKeyPath) So(resp, ShouldNotBeNil) So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "GET,POST,DELETE,OPTIONS") So(resp.Header().Get("Access-Control-Allow-Origin"), ShouldResemble, "*") @@ -155,7 +155,7 @@ func TestAPIKeys(t *testing.T) { So(err, ShouldBeNil) Convey("API key retrieved with basic auth", func() { - resp, err := resty.R(). + resp, err := resty.New().R(). SetBody(reqBody). SetBasicAuth(username, password). Post(baseURL + constants.APIKeyPath) @@ -173,7 +173,7 @@ func TestAPIKeys(t *testing.T) { email := user.Email So(email, ShouldNotBeEmpty) - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(username, apiKeyResponse.APIKey). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) @@ -181,7 +181,7 @@ func TestAPIKeys(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) // get API key list with basic auth - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(username, password). Get(baseURL + constants.APIKeyPath) So(err, ShouldBeNil) @@ -199,7 +199,7 @@ func TestAPIKeys(t *testing.T) { So(apiKeyListResponse.APIKeys[0].UUID, ShouldEqual, apiKeyResponse.APIKeyDetails.UUID) // add another one - resp, err = resty.R(). + resp, err = resty.New().R(). SetBody(reqBody). SetBasicAuth(username, password). Post(baseURL + constants.APIKeyPath) @@ -210,7 +210,7 @@ func TestAPIKeys(t *testing.T) { err = json.Unmarshal(resp.Body(), &apiKeyResponse) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(username, apiKeyResponse.APIKey). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) @@ -218,7 +218,7 @@ func TestAPIKeys(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) // get API key list with api key auth - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(username, apiKeyResponse.APIKey). Get(baseURL + constants.APIKeyPath) So(err, ShouldBeNil) @@ -450,7 +450,7 @@ func TestAPIKeys(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) // get API key list - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(email, apiKeyResponse.APIKey). Get(baseURL + constants.APIKeyPath) So(err, ShouldBeNil) diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index d6508041a..b7f09d9df 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -508,7 +508,7 @@ func TestObjectStorageController(t *testing.T) { } // create s3 bucket - _, err = resty.R().Put("http://" + os.Getenv("S3MOCK_ENDPOINT") + "/" + bucket) + _, err = resty.New().R().Put("http://" + os.Getenv("S3MOCK_ENDPOINT") + "/" + bucket) if err != nil { panic(err) } @@ -597,13 +597,13 @@ func TestHtpasswdSingleCred(t *testing.T) { defer cm.StopServer() // with creds, should get expected status code - resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(user, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) header := []string{"Authorization,content-type," + constants.SessionClientHeaderName} - resp, _ = resty.R().SetBasicAuth(user, password).Options(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(user, password).Options(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) So(len(resp.Header()), ShouldEqual, 5) @@ -611,7 +611,7 @@ func TestHtpasswdSingleCred(t *testing.T) { So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "GET,OPTIONS") // with invalid creds, it should fail - resp, _ = resty.R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }() @@ -665,7 +665,7 @@ func TestAllowMethodsHeader(t *testing.T) { ctlrManager.StartAndWait(port) defer ctlrManager.StopServer() - simpleUserClient := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + simpleUserClient := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) digest := godigest.FromString("digest") @@ -739,16 +739,16 @@ func TestHtpasswdTwoCreds(t *testing.T) { defer cm.StopServer() // with creds, should get expected status code - resp, _ := resty.R().SetBasicAuth(user1, password1).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(user1, password1).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, _ = resty.R().SetBasicAuth(user2, password2).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(user2, password2).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with invalid creds, it should fail - resp, _ = resty.R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }() @@ -793,13 +793,13 @@ func TestHtpasswdFiveCreds(t *testing.T) { // with creds, should get expected status code for key, val := range tests { - resp, _ := resty.R().SetBasicAuth(key, val).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(key, val).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) } // with invalid creds, it should fail - resp, _ := resty.R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }() @@ -940,7 +940,7 @@ func TestBasicAuth(t *testing.T) { defer cm.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -951,11 +951,11 @@ func TestBasicAuth(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -976,7 +976,7 @@ func TestBlobReferenced(t *testing.T) { defer cm.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -993,25 +993,25 @@ func TestBlobReferenced(t *testing.T) { configDigest := img.ConfigDescriptor.Digest // delete manifest blob - resp, err = resty.R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + manifestDigest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + manifestDigest.String()) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusMethodNotAllowed) // delete config blob - resp, err = resty.R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + configDigest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + configDigest.String()) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusMethodNotAllowed) // delete manifest with manifest api method - resp, err = resty.R().Delete(baseURL + "/v2/" + repoName + "/manifests/" + manifestDigest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + repoName + "/manifests/" + manifestDigest.String()) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete blob should work after manifest is deleted - resp, err = resty.R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + configDigest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + configDigest.String()) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) @@ -1040,7 +1040,7 @@ func TestScaleOutRequestProxy(t *testing.T) { defer cm.StopServer() Convey("Controller should start up and respond without error", func() { - resp, err := resty.R().Get(test.GetBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1054,7 +1054,7 @@ func TestScaleOutRequestProxy(t *testing.T) { err := UploadImage(img, test.GetBaseURL(port), repoName, "1.0") So(err, ShouldBeNil) - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1097,7 +1097,7 @@ func TestScaleOutRequestProxy(t *testing.T) { defer cm.StopServer() Convey("Controller should start up and respond without error", func() { - resp, err := resty.R().Get(test.GetBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1111,7 +1111,7 @@ func TestScaleOutRequestProxy(t *testing.T) { So(err, ShouldNotBeNil) So(err.Error(), ShouldEqual, "can't post blob") - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -1149,7 +1149,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("All 3 controllers should start up and respond without error", func() { for _, port := range ports { - resp, err := resty.R().Get(test.GetBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1167,7 +1167,7 @@ func TestScaleOutRequestProxy(t *testing.T) { // Query all 3 instances and expect the same response for _, port := range ports { - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetBaseURL(port), repoName)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1246,7 +1246,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("All 3 controllers should start up and respond without error", func() { for _, port := range ports { - resp, err := resty.R().SetBasicAuth(username, password).Get(test.GetSecureBaseURL(port) + "/v2/") + resp, err := resty.New().R().SetBasicAuth(username, password).Get(test.GetSecureBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1264,7 +1264,7 @@ func TestScaleOutRequestProxy(t *testing.T) { // Query all 3 instances and expect the same response for _, port := range ports { - resp, err := resty.R().SetBasicAuth(username, password).Get( + resp, err := resty.New().R().SetBasicAuth(username, password).Get( fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(port), repoName), ) So(err, ShouldBeNil) @@ -1332,7 +1332,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Both controllers should start up and respond without error", func() { for _, port := range ports { - resp, err := resty.R().Get(test.GetSecureBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetSecureBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1341,7 +1341,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Proxying a request should fail with an error", func() { // debian gets proxied to the second instance - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -1396,7 +1396,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Both controllers should start up and respond without error", func() { for _, port := range ports { - resp, err := resty.R().Get(test.GetSecureBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetSecureBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1405,7 +1405,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Proxying a request should fail with an error", func() { // debian gets proxied to the second instance - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -1461,7 +1461,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Both controllers should start up and respond without error", func() { for _, port := range ports { - resp, err := resty.R().Get(test.GetSecureBaseURL(port) + "/v2/") + resp, err := resty.New().R().Get(test.GetSecureBaseURL(port) + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1470,7 +1470,7 @@ func TestScaleOutRequestProxy(t *testing.T) { Convey("Proxying a request should fail with an error", func() { // debian gets proxied to the second instance - resp, err := resty.R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) + resp, err := resty.New().R().Get(fmt.Sprintf("%s/v2/%s/tags/list", test.GetSecureBaseURL(ports[0]), "debian")) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -1503,7 +1503,7 @@ func TestPrintTracebackOnPanic(t *testing.T) { ctlr.StoreController.SubStore = make(map[string]storageTypes.ImageStore) ctlr.StoreController.SubStore["/a"] = nil - resp, err := resty.R().Get(baseURL + "/v2/_catalog") + resp, err := resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -1840,7 +1840,7 @@ func TestMultipleInstance(t *testing.T) { defer cm.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -1851,11 +1851,11 @@ func TestMultipleInstance(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -1954,13 +1954,13 @@ func TestTLSWithBasicAuth(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without creds, should get access error - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -1971,11 +1971,11 @@ func TestTLSWithBasicAuth(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -2033,27 +2033,27 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without creds, should still be allowed to access - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // without creds, writes should fail - resp, err = resty.R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") + resp, err = resty.New().R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) @@ -2104,7 +2104,7 @@ func TestMutualTLSAuthWithUserPermissions(t *testing.T) { defer cm.StopServer() - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -2120,36 +2120,36 @@ func TestMutualTLSAuthWithUserPermissions(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without creds, should succeed - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(secureBaseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with creds, should get expected status code - resp, _ = resty.R().Get(secureBaseURL) + resp, _ = resty.New().R().Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // reading a repo should not get 403 - resp, err = resty.R().Get(secureBaseURL + "/v2/repo/tags/list") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/repo/tags/list") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // without creds, writes should fail - resp, err = resty.R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") + resp, err = resty.New().R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusForbidden) // empty default authorization and give user the permission to create repoPolicy.Policies[0].Actions = append(repoPolicy.Policies[0].Actions, "create") conf.HTTP.AccessControl.Repositories[test.AuthorizationAllRepos] = repoPolicy - resp, err = resty.R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") + resp, err = resty.New().R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) }) @@ -2333,7 +2333,7 @@ func TestMutualTLSAuthWithoutCN(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without TLS mutual auth setup should get certificate error - resp, _ := resty.R().Get(secureBaseURL + "/v2/_catalog") + resp, _ := resty.New().R().Get(secureBaseURL + "/v2/_catalog") So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) } @@ -2370,20 +2370,20 @@ func TestTLSMutualAuth(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without client certs and creds, should get conn error - _, err = resty.R().Get(secureBaseURL) + _, err = resty.New().R().Get(secureBaseURL) So(err, ShouldNotBeNil) username, seedUser := test.GenerateRandomString() password, seedPass := test.GenerateRandomString() ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password") // with creds but without certs, should get conn error - _, err = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + _, err = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(err, ShouldNotBeNil) // setup TLS mutual auth @@ -2395,18 +2395,18 @@ func TestTLSMutualAuth(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without creds, should succeed - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with client certs and creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // with client certs, creds shouldn't matter - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -2541,13 +2541,13 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without client certs and creds, reads are allowed - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -2555,12 +2555,12 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) { password, seedPass := test.GenerateRandomString() ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password") // with creds but without certs, reads are allowed - resp, err = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // without creds, writes should fail - resp, err = resty.R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") + resp, err = resty.New().R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -2573,18 +2573,18 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without creds, should succeed - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with client certs and creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // with client certs, creds shouldn't matter - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -2635,19 +2635,19 @@ func TestTLSMutualAndBasicAuth(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without client certs and creds, should fail - _, err = resty.R().Get(secureBaseURL) + _, err = resty.New().R().Get(secureBaseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // with creds but without certs, should succeed - _, err = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + _, err = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -2661,17 +2661,17 @@ func TestTLSMutualAndBasicAuth(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without creds, should get access error - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // with client certs and creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -2730,19 +2730,19 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) { defer cm.StopServer() // accessing insecure HTTP site should fail - resp, err := resty.R().Get(baseURL) + resp, err := resty.New().R().Get(baseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without client certs and creds, should fail - _, err = resty.R().Get(secureBaseURL) + _, err = resty.New().R().Get(secureBaseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // with creds but without certs, should succeed - _, err = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + _, err = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -2756,21 +2756,21 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) { defer func() { resty.SetCertificates(tls.Certificate{}) }() // with client certs but without creds, reads should succeed - resp, err = resty.R().Get(secureBaseURL + "/v2/") + resp, err = resty.New().R().Get(secureBaseURL + "/v2/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with only client certs, writes should fail - resp, err = resty.R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") + resp, err = resty.New().R().Post(secureBaseURL + "/v2/repo/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // with client certs and creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(secureBaseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -2909,7 +2909,7 @@ func TestBasicAuthWithLDAP(t *testing.T) { defer cm.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -2920,16 +2920,16 @@ func TestBasicAuthWithLDAP(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // missing password - resp, _ = resty.R().SetBasicAuth(username, "").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, "").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) @@ -3001,7 +3001,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { time.Sleep(time.Second * 2) // test if the credentials work - resp, _ := resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -3012,7 +3012,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { for i := 0; i < 10; i++ { // test if the credentials don't work - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) if resp.StatusCode() != http.StatusOK { @@ -3029,7 +3029,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { for i := 0; i < 10; i++ { // test if the credentials don't work - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) if resp.StatusCode() == http.StatusOK { @@ -3056,7 +3056,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { for i := 0; i < 10; i++ { // test if the credentials don't work - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) if resp.StatusCode() != http.StatusOK { @@ -3073,7 +3073,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { for i := 0; i < 10; i++ { // test if the credentials don't work - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) if resp.StatusCode() == http.StatusOK { @@ -3102,7 +3102,7 @@ func TestBasicAuthWithReloadedCredentials(t *testing.T) { for i := 0; i < 10; i++ { // test if the credentials don't work - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) if resp.StatusCode() == http.StatusOK { @@ -3149,7 +3149,7 @@ func TestLDAPWithoutCreds(t *testing.T) { defer cm.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -3159,15 +3159,15 @@ func TestLDAPWithoutCreds(t *testing.T) { err = json.Unmarshal(resp.Body(), &e) So(err, ShouldBeNil) - resp, _ = resty.R().SetBasicAuth(username, "").Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, "").Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, "").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, "").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -3194,7 +3194,7 @@ func TestLDAPWithoutCreds(t *testing.T) { defer cm.StopServer() - resp, _ := resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) @@ -3266,7 +3266,7 @@ func TestBasicAuthWithLDAPFromFile(t *testing.T) { test.WaitTillServerReady(baseURL) // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -3277,16 +3277,16 @@ func TestBasicAuthWithLDAPFromFile(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // missing password - resp, _ = resty.R().SetBasicAuth(username, "").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, "").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) @@ -3709,13 +3709,13 @@ func TestBearerAuth(t *testing.T) { blob := []byte("hello, blob!") digest := godigest.FromBytes(blob).String() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader := authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). Get(authorizationHeader.Realm) So(err, ShouldBeNil) @@ -3727,7 +3727,7 @@ func TestBearerAuth(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/") So(err, ShouldBeNil) @@ -3735,14 +3735,14 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) // trigger decode error - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+"invalidToken"). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) - resp, err = resty.R().SetHeader("Authorization", + resp, err = resty.New().R().SetHeader("Authorization", "Bearer "+goodToken.AccessToken).Options(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -3754,13 +3754,13 @@ func TestBearerAuth(t *testing.T) { ctlr.Log.Info().Int64("seed1", seed1).Int64("seed2", seed2).Msg("random seeds for repoName") - resp, err = resty.R().Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3770,7 +3770,7 @@ func TestBearerAuth(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") So(err, ShouldBeNil) @@ -3778,7 +3778,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := resp.Header().Get("Location") - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", digest). @@ -3789,7 +3789,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3799,7 +3799,7 @@ func TestBearerAuth(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). @@ -3810,7 +3810,7 @@ func TestBearerAuth(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/" + repoName + "/tags/list") So(err, ShouldBeNil) @@ -3818,7 +3818,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3828,21 +3828,21 @@ func TestBearerAuth(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/" + repoName + "/tags/list") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R(). + resp, err = resty.New().R(). Post(baseURL + "/v2/" + UnauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3855,7 +3855,7 @@ func TestBearerAuth(t *testing.T) { err = json.Unmarshal(resp.Body(), &badToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+badToken.AccessToken). Post(baseURL + "/v2/" + UnauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) @@ -3924,13 +3924,13 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { blob := []byte("hello, blob!") digest := godigest.FromBytes(blob).String() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader := authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3943,7 +3943,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/") So(err, ShouldBeNil) @@ -3956,13 +3956,13 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { ctlr.Log.Info().Int64("seed1", seed1).Int64("seed2", seed2).Msg("random seeds for repoName") - resp, err = resty.R().Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3972,7 +3972,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") So(err, ShouldBeNil) @@ -3980,7 +3980,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := resp.Header().Get("Location") - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", digest). @@ -3991,7 +3991,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -4001,7 +4001,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). @@ -4012,7 +4012,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/" + repoName + "/tags/list") So(err, ShouldBeNil) @@ -4020,7 +4020,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -4030,21 +4030,21 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/" + repoName + "/tags/list") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R(). + resp, err = resty.New().R(). Post(baseURL + "/v2/" + UnauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -4056,7 +4056,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) { err = json.Unmarshal(resp.Body(), &badToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+badToken.AccessToken). Post(baseURL + "/v2/" + UnauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) @@ -4606,7 +4606,7 @@ func TestIsOpenIDEnabled(t *testing.T) { defer cm.StopServer() test.WaitTillServerReady(baseURL) - resp, err := resty.R(). + resp, err := resty.New().R(). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -4642,7 +4642,7 @@ func TestIsOpenIDEnabled(t *testing.T) { // it will work because we have an invalid provider, and no other authn enabled, so no authn enabled // normally an invalid provider will exit with error in cli validations - resp, err := resty.R(). + resp, err := resty.New().R(). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -5322,25 +5322,25 @@ func TestGetUsername(t *testing.T) { defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // test base64 encode - resp, err = resty.R().SetHeader("Authorization", "Basic should fail").Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().SetHeader("Authorization", "Basic should fail").Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // test "username:password" encoding - resp, err = resty.R().SetHeader("Authorization", "Basic dGVzdA==").Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().SetHeader("Authorization", "Basic dGVzdA==").Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // failed parsing authorization header - resp, err = resty.R().SetHeader("Authorization", "Basic ").Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().SetHeader("Authorization", "Basic ").Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -5350,7 +5350,7 @@ func TestGetUsername(t *testing.T) { err = json.Unmarshal(resp.Body(), &e) So(err, ShouldBeNil) - resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5504,12 +5504,12 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { blob := []byte("hello, blob!") digest := godigest.FromBytes(blob).String() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5520,7 +5520,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { So(err, ShouldBeNil) // should get 401 without create - resp, err = resty.R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -5531,14 +5531,14 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { } // now it should get 202 - resp, err = resty.R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := resp.Header().Get("Location") // uploading blob should get 201 - resp, err = resty.R().SetHeader("Content-Length", strconv.Itoa(len(blob))). + resp, err = resty.New().R().SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", digest). SetBody(blob). @@ -5549,14 +5549,14 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { cblob, cdigest := GetRandomImageConfig() - resp, err = resty.R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc = test.Location(baseURL, resp) // uploading blob should get 201 - resp, err = resty.R().SetHeader("Content-Length", strconv.Itoa(len(cblob))). + resp, err = resty.New().R().SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", cdigest.String()). SetBody(cblob). @@ -5583,7 +5583,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { manifestBlob, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestBlob). Put(baseURL + "/v2/" + TestRepo + "/manifests/0.0.2") @@ -5593,14 +5593,14 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { updateBlob := []byte("Hello, blob update!") - resp, err = resty.R(). + resp, err = resty.New().R(). Post(baseURL + "/v2/" + TestRepo + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc = test.Location(baseURL, resp) // uploading blob should get 201 - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(updateBlob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", string(godigest.FromBytes(updateBlob))). @@ -5629,14 +5629,14 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { So(err, ShouldBeNil) // update manifest should get 401 without update perm - resp, err = resty.R().SetBody(updatedManifestBlob). + resp, err = resty.New().R().SetBody(updatedManifestBlob). Put(baseURL + "/v2/" + TestRepo + "/manifests/0.0.2") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // get the manifest and check if it's the old one - resp, err = resty.R(). + resp, err = resty.New().R(). Get(baseURL + "/v2/" + TestRepo + "/manifests/0.0.2") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -5650,7 +5650,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { } // update manifest should get 201 with update perm - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody(updatedManifestBlob). Put(baseURL + "/v2/" + TestRepo + "/manifests/0.0.2") @@ -5659,14 +5659,14 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusCreated) // get the manifest and check if it's the new updated one - resp, err = resty.R(). + resp, err = resty.New().R(). Get(baseURL + "/v2/" + TestRepo + "/manifests/0.0.2") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldResemble, updatedManifestBlob) - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5688,7 +5688,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { So(err, ShouldBeNil) // should not have read rights on zot-test - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5703,7 +5703,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) { AnonymousPolicy: []string{"read"}, } - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -5770,13 +5770,13 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) // /v2 access // Can access /v2 without credentials - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // Can access /v2 without credentials and with X-Zot-Api-Client=zot-ui - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue). Get(baseURL + "/v2/") So(err, ShouldBeNil) @@ -5784,21 +5784,21 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // Can access /v2 with correct credentials - resp, err = resty.R().SetBasicAuth(htpasswdUsername, htpasswdPassword). + resp, err = resty.New().R().SetBasicAuth(htpasswdUsername, htpasswdPassword). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // Fail to access /v2 with incorrect credentials - resp, err = resty.R().SetBasicAuth(htpasswdUsername, badpassphrase). + resp, err = resty.New().R().SetBasicAuth(htpasswdUsername, badpassphrase). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // Catalog access - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5808,7 +5808,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) err = json.Unmarshal(resp.Body(), &apiError) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) @@ -5819,7 +5819,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) err = json.Unmarshal(resp.Body(), &apiError) So(err, ShouldBeNil) - resp, err = resty.R().SetBasicAuth(htpasswdUsername, htpasswdPassword). + resp, err = resty.New().R().SetBasicAuth(htpasswdUsername, htpasswdPassword). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -5829,7 +5829,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) err = json.Unmarshal(resp.Body(), &apiError) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(htpasswdUsername, badpassphrase). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) @@ -5879,7 +5879,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) Repositories []string `json:"repositories"` }{} - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5893,7 +5893,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) Repositories []string `json:"repositories"` }{} - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) @@ -5909,7 +5909,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) Repositories []string `json:"repositories"` }{} - resp, err = resty.R().SetBasicAuth(htpasswdUsername, htpasswdPassword). + resp, err = resty.New().R().SetBasicAuth(htpasswdUsername, htpasswdPassword). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -5920,7 +5920,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T) So(len(catalog.Repositories), ShouldEqual, 1) So(catalog.Repositories, ShouldContain, TestRepo) - resp, err = resty.R().SetBasicAuth(htpasswdUsername, badpassphrase). + resp, err = resty.New().R().SetBasicAuth(htpasswdUsername, badpassphrase). Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -6194,7 +6194,7 @@ func TestHTTPReadOnly(t *testing.T) { defer cm.StopServer() // with creds, should get expected status code - resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/") + resp, _ := resty.New().R().SetBasicAuth(user, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6206,14 +6206,14 @@ func TestHTTPReadOnly(t *testing.T) { ctlr.Log.Info().Int64("seed1", seed1).Int64("seed2", seed2).Msg("random seeds for repoName") // with creds, any modifications should still fail on read-only mode - resp, err := resty.R().SetBasicAuth(user, password). + resp, err := resty.New().R().SetBasicAuth(user, password). Post(baseURL + "/v2/" + repoName + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusForbidden) // with invalid creds, it should fail - resp, _ = resty.R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth("chuck", "chuck").Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }() @@ -7023,13 +7023,13 @@ func TestImageSignatures(t *testing.T) { So(err, ShouldBeNil) // check unsupported manifest media type - resp, err := resty.R().SetHeader("Content-Type", "application/vnd.unsupported.image.manifest.v1+json"). + resp, err := resty.New().R().SetHeader("Content-Type", "application/vnd.unsupported.image.manifest.v1+json"). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnsupportedMediaType) // check invalid content with artifact media type - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody([]byte("bogus")).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) @@ -7037,7 +7037,7 @@ func TestImageSignatures(t *testing.T) { Convey("Validate corrupted signature", func() { // verify with corrupted signature - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7050,7 +7050,7 @@ func TestImageSignatures(t *testing.T) { err = os.WriteFile(path.Join(dir, repoName, "blobs", strings.ReplaceAll(refs.Manifests[0].Digest.String(), ":", "/")), []byte("corrupt"), 0o600) So(err, ShouldBeNil) - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -7061,7 +7061,7 @@ func TestImageSignatures(t *testing.T) { Convey("Validate deleted signature", func() { // verify with corrupted signature - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7073,7 +7073,7 @@ func TestImageSignatures(t *testing.T) { err = os.Remove(path.Join(dir, repoName, "blobs", strings.ReplaceAll(refs.Manifests[0].Digest.String(), ":", "/"))) So(err, ShouldBeNil) - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -7135,7 +7135,7 @@ func TestManifestValidation(t *testing.T) { mcontent, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -7158,7 +7158,7 @@ func TestManifestValidation(t *testing.T) { mcontent, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7195,7 +7195,7 @@ func TestManifestValidation(t *testing.T) { mcontent, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7226,7 +7226,7 @@ func TestManifestValidation(t *testing.T) { mcontent, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7249,7 +7249,7 @@ func TestManifestValidation(t *testing.T) { indexContent, err := json.Marshal(index) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(indexContent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/index", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -7270,7 +7270,7 @@ func TestManifestValidation(t *testing.T) { indexContent, err := json.Marshal(index) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(indexContent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/index", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7298,7 +7298,7 @@ func TestManifestValidation(t *testing.T) { indexContent, err := json.Marshal(index) So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(indexContent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/index", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7335,7 +7335,7 @@ func TestArtifactReferences(t *testing.T) { artifactType := "application/vnd.example.icecream.v1" Convey("Validate Image Manifest Reference", func() { - resp, err := resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) + resp, err := resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7347,13 +7347,13 @@ func TestArtifactReferences(t *testing.T) { // now upload a reference // upload image config blob - resp, err = resty.R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) + resp, err = resty.New().R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) cblob, cdigest := getEmptyImageConfig() - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -7389,28 +7389,28 @@ func TestArtifactReferences(t *testing.T) { manifest.SchemaVersion = 2 Convey("Using invalid content", func() { - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody([]byte("invalid data")).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // unknown repo will return status not found - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", "unknown", digest.String())) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", "unknown", digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}). + resp, err = resty.New().R().SetQueryParams(map[string]string{"artifactType": artifactType}). Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // create a bad manifest (constructed manually) content := `{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","subject":{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:71dbae9d7e6445fb5e0b11328e941b8e8937fdd52465079f536ce44bb78796ed","size":406}}` //nolint: lll - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7428,7 +7428,7 @@ func TestArtifactReferences(t *testing.T) { mcontent, err = json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -7438,13 +7438,13 @@ func TestArtifactReferences(t *testing.T) { mcontent, err = json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // upload image config blob - resp, err = resty.R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) + resp, err = resty.New().R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -7452,7 +7452,7 @@ func TestArtifactReferences(t *testing.T) { cdigest = godigest.FromBytes(cblob) So(cdigest, ShouldNotBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -7477,7 +7477,7 @@ func TestArtifactReferences(t *testing.T) { digest = godigest.FromBytes(mcontent) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7497,7 +7497,7 @@ func TestArtifactReferences(t *testing.T) { So(err, ShouldBeNil) // should fail because config is of type image and blob is not uploaded - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -7509,7 +7509,7 @@ func TestArtifactReferences(t *testing.T) { So(err, ShouldBeNil) // should not fail - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(mcontent).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -7518,33 +7518,33 @@ func TestArtifactReferences(t *testing.T) { Convey("Using valid content", func() { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetQueryParams(map[string]string{"artifact": "invalid"}). + resp, err = resty.New().R().SetQueryParams(map[string]string{"artifact": "invalid"}). Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": "invalid"}). + resp, err = resty.New().R().SetQueryParams(map[string]string{"artifactType": "invalid"}). Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}). + resp, err = resty.New().R().SetQueryParams(map[string]string{"artifactType": artifactType}). Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex) So(resp.Header().Get("OCI-Filters-Applied"), ShouldEqual, "artifactType") //nolint:canonicalheader - resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType + + resp, err = resty.New().R().SetQueryParams(map[string]string{"artifactType": artifactType + ",otherArtType"}).Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String())) So(err, ShouldBeNil) @@ -8332,7 +8332,7 @@ func TestStorageCommit(t *testing.T) { _, _ = Print("\nManifests") // check a non-existent manifest - resp, err := resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err := resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). Head(baseURL + "/v2/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -8350,7 +8350,7 @@ func TestStorageCommit(t *testing.T) { digest := image.ManifestDescriptor.Digest So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8358,7 +8358,7 @@ func TestStorageCommit(t *testing.T) { So(digestHdr, ShouldNotBeEmpty) So(digestHdr, ShouldEqual, digest.String()) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8374,7 +8374,7 @@ func TestStorageCommit(t *testing.T) { err = UploadImage(image, baseURL, repoName, "test:2.0") So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8383,61 +8383,61 @@ func TestStorageCommit(t *testing.T) { So(digestHdr, ShouldEqual, digest.String()) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // delete manifest by tag should pass - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete manifest by digest (1.0 deleted but 1.0.1 has same reference) - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete manifest by digest - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // delete again should fail - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:2.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:2.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) @@ -8465,7 +8465,7 @@ func TestManifestImageIndex(t *testing.T) { img := CreateImageWith().RandomLayers(1, 2).DefaultConfig().Build() // check a non-existent manifest - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). Head(baseURL + "/v2/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -8482,7 +8482,7 @@ func TestManifestImageIndex(t *testing.T) { So(digest, ShouldNotBeNil) m1content := content - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + "/v2/index/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8493,7 +8493,7 @@ func TestManifestImageIndex(t *testing.T) { // create another manifest but upload using its sha256 reference // upload image config blob - resp, err = resty.R().Post(baseURL + "/v2/index/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/index/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) @@ -8507,7 +8507,7 @@ func TestManifestImageIndex(t *testing.T) { m2dgst := digest m2size := len(content) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/index/manifests/%s", digest)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8524,7 +8524,7 @@ func TestManifestImageIndex(t *testing.T) { content := img.ManifestDescriptor.Data digest = img.ManifestDescriptor.Digest - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + "/v2/index/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8553,7 +8553,7 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) index1dgst := digest - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8561,7 +8561,7 @@ func TestManifestImageIndex(t *testing.T) { So(digestHdr, ShouldNotBeEmpty) So(digestHdr, ShouldEqual, digest.String()) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -8578,7 +8578,7 @@ func TestManifestImageIndex(t *testing.T) { m4dgst := digest m4size := len(content) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + "/v2/index/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8606,7 +8606,7 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:index2") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8614,7 +8614,7 @@ func TestManifestImageIndex(t *testing.T) { So(digestHdr, ShouldNotBeEmpty) So(digestHdr, ShouldEqual, digest.String()) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index2") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -8659,7 +8659,7 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:index3") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8684,7 +8684,7 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/index/manifests/%s", digest)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8694,28 +8694,28 @@ func TestManifestImageIndex(t *testing.T) { }) Convey("Deleting manifest contained by a multiarch image should not be allowed", func() { - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/" + m2dgst.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/" + m2dgst.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusMethodNotAllowed) }) Convey("Deleting an image index", func() { // delete manifest by tag should pass - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/test:index3") + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/test:index3") So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index3") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/test:index1") + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index2") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -8725,21 +8725,21 @@ func TestManifestImageIndex(t *testing.T) { Convey("Deleting an image index by digest", func() { // delete manifest by tag should pass - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/test:index3") + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/test:index3") So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index3") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) + resp, err = resty.New().R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index2") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -8756,7 +8756,7 @@ func TestManifestImageIndex(t *testing.T) { content = img.ManifestDescriptor.Data digest = img.ManifestDescriptor.Digest - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/index/manifests/%s", digest)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8779,7 +8779,7 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8787,7 +8787,7 @@ func TestManifestImageIndex(t *testing.T) { So(digestHdr, ShouldNotBeEmpty) So(digestHdr, ShouldEqual, digest.String()) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -8795,10 +8795,10 @@ func TestManifestImageIndex(t *testing.T) { So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) // delete manifest by tag should pass - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/test:index1") + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -8809,9 +8809,9 @@ func TestManifestImageIndex(t *testing.T) { Convey("Delete index", func() { err = os.Remove(path.Join(dir, "index", "blobs", index1dgst.Algorithm().String(), index1dgst.Encoded())) So(err, ShouldBeNil) - resp, err = resty.R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) + resp, err = resty.New().R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -8822,9 +8822,9 @@ func TestManifestImageIndex(t *testing.T) { err = os.WriteFile(path.Join(dir, "index", "blobs", index1dgst.Algorithm().String(), index1dgst.Encoded()), []byte("deadbeef"), storageConstants.DefaultFilePerms) So(err, ShouldBeNil) - resp, err = resty.R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) + resp, err = resty.New().R().Delete(baseURL + fmt.Sprintf("/v2/index/manifests/%s", index1dgst)) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -8849,13 +8849,13 @@ func TestManifestImageIndex(t *testing.T) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // previously an image index, try writing a manifest - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(m1content).Put(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -8902,7 +8902,7 @@ func TestManifestCollision(t *testing.T) { So(err, ShouldBeNil) // check a non-existent manifest - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). Head(baseURL + "/v2/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -8914,7 +8914,7 @@ func TestManifestCollision(t *testing.T) { So(err, ShouldBeNil) // Deletion should fail if using digest - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusConflict) @@ -8923,15 +8923,15 @@ func TestManifestCollision(t *testing.T) { repoPolicy.AnonymousPolicy = []string{"read", "delete"} conf.HTTP.AccessControl.Repositories[test.AuthorizationAllRepos] = repoPolicy - resp, err = resty.R().Delete(baseURL + "/v2/index/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/index/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Get(baseURL + "/v2/index/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/index/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/index/manifests/test:2.0") + resp, err = resty.New().R().Get(baseURL + "/v2/index/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -8953,7 +8953,7 @@ func TestPullRange(t *testing.T) { defer cm.StopServer() // create a blob/layer - resp, err := resty.R().Post(baseURL + "/v2/index/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/index/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -8964,7 +8964,7 @@ func TestPullRange(t *testing.T) { _, err = os.Stat(path.Join(dir, "index")) So(err, ShouldBeNil) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -8972,7 +8972,7 @@ func TestPullRange(t *testing.T) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) // monolithic blob upload: success - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -8984,44 +8984,44 @@ func TestPullRange(t *testing.T) { blobLoc = baseURL + blobLoc Convey("Range is supported using 'bytes'", func() { - resp, err = resty.R().Head(blobLoc) + resp, err = resty.New().R().Head(blobLoc) So(err, ShouldBeNil) So(resp.Header().Get("Accept-Ranges"), ShouldEqual, "bytes") So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) Convey("Get a range of bytes", func() { - resp, err = resty.R().SetHeader("Range", "bytes=0-").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, strconv.Itoa(len(content))) So(resp.Body(), ShouldResemble, content) - resp, err = resty.R().SetHeader("Range", "bytes=0-100").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-100").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, strconv.Itoa(len(content))) So(resp.Body(), ShouldResemble, content) - resp, err = resty.R().SetHeader("Range", "bytes=0-10").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-10").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, strconv.Itoa(len(content))) So(resp.Body(), ShouldResemble, content) - resp, err = resty.R().SetHeader("Range", "bytes=0-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, "1") So(resp.Body(), ShouldResemble, content[0:1]) - resp, err = resty.R().SetHeader("Range", "bytes=0-1").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-1").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, "2") So(resp.Body(), ShouldResemble, content[0:2]) - resp, err = resty.R().SetHeader("Range", "bytes=2-3").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=2-3").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusPartialContent) So(resp.Header().Get("Content-Length"), ShouldEqual, "2") @@ -9029,71 +9029,71 @@ func TestPullRange(t *testing.T) { }) Convey("Negative cases", func() { - resp, err = resty.R().SetHeader("Range", "=0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "=0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "=a").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "=a").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "=").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "=").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "byte=").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "byte=").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "byte=-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "byte=-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "byte=0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "byte=0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "octet=-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "octet=-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=1-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=1-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=-1-0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=-1-0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=-1--0").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=-1--0").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=1--2").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=1--2").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=0-a").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=0-a").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=a-10").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=a-10").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) - resp, err = resty.R().SetHeader("Range", "bytes=a-b").Get(blobLoc) + resp, err = resty.New().R().SetHeader("Range", "bytes=a-b").Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) }) @@ -9119,7 +9119,7 @@ func TestInjectInterruptedImageManifest(t *testing.T) { Convey("Upload a blob & a config blob; Create an image manifest", func() { // create a blob/layer - resp, err := resty.R().Post(baseURL + "/v2/repotest/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repotest/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -9130,7 +9130,7 @@ func TestInjectInterruptedImageManifest(t *testing.T) { _, err = os.Stat(path.Join(dir, "repotest")) So(err, ShouldBeNil) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -9138,7 +9138,7 @@ func TestInjectInterruptedImageManifest(t *testing.T) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) // monolithic blob upload: success - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -9148,13 +9148,13 @@ func TestInjectInterruptedImageManifest(t *testing.T) { So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // upload image config blob - resp, err = resty.R().Post(baseURL + "/v2/repotest/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/repotest/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc = test.Location(baseURL, resp) cblob, cdigest := GetRandomImageConfig() - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -9232,7 +9232,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) { rthdlr := api.NewRouteHandler(ctlr) // create a blob/layer - resp, err := resty.R().Post(baseURL + "/v2/repotest/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repotest/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -9243,7 +9243,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) { _, err = os.Stat(path.Join(dir, "repotest")) So(err, ShouldBeNil) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -9273,7 +9273,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode, ShouldEqual, http.StatusInternalServerError) } else { - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream"). SetBody(content).Put(loc) So(err, ShouldBeNil) @@ -9286,13 +9286,13 @@ func TestInjectTooManyOpenFiles(t *testing.T) { } // upload image config blob - resp, err = resty.R().Post(baseURL + "/v2/repotest/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/repotest/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc = test.Location(baseURL, resp) cblob, cdigest := GetRandomImageConfig() - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -9393,7 +9393,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) { }) Convey("when index.json is not in json format", func() { - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/repotest/manifests/v1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -9409,7 +9409,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) { err = os.WriteFile(indexFile, indexContent, 0o600) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/repotest/manifests/v1.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -9488,7 +9488,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { ImageRetention: ctlr.Config.Storage.Retention, }, ctlr.Audit, ctlr.Log) - resp, err := resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, tag)) + resp, err := resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, tag)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) digest := godigest.FromBytes(resp.Body()) @@ -9540,7 +9540,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { // get cosign signature manifest cosignTag := strings.Replace(digest.String(), ":", "-", 1) + "." + remote.SignatureTagSuffix - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, cosignTag)) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, cosignTag)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -9548,7 +9548,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { So(cosignDigest, ShouldNotBeEmpty) // get notation signature manifest - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -9654,11 +9654,11 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { So(ok, ShouldBeFalse) // both signatures should be gc'ed - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, cosignTag)) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, cosignTag)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -9667,7 +9667,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { So(err, ShouldBeNil) So(len(index.Manifests), ShouldEqual, 0) - resp, err = resty.R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( + resp, err = resty.New().R().SetQueryParam("artifactType", notreg.ArtifactTypeNotation).Get( fmt.Sprintf("%s/v2/%s/referrers/%s", baseURL, repoName, newManifestDigest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -9677,7 +9677,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { So(len(index.Manifests), ShouldEqual, 0) // untagged image should also be gc'ed - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, untaggedManifestDigest)) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, untaggedManifestDigest)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -9723,7 +9723,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { ImageRetention: ctlr.Config.Storage.Retention, }, ctlr.Audit, ctlr.Log) - resp, err := resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, tag)) + resp, err := resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, tag)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) digest := godigest.FromBytes(resp.Body()) @@ -9759,7 +9759,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { time.Sleep(1 * time.Second) // upload image index - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/latest", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -9767,7 +9767,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { err = gc.CleanRepo(ctx, repoName) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(baseURL + fmt.Sprintf("/v2/%s/manifests/latest", repoName)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -9776,7 +9776,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { // make sure manifests which are part of image index are not gc'ed for _, manifest := range index.Manifests { - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, manifest.Digest.String())) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, manifest.Digest.String())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) } @@ -10022,7 +10022,7 @@ func TestSearchRoutes(t *testing.T) { } } }` - resp, err := resty.R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + + resp, err := resty.New().R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -10030,7 +10030,7 @@ func TestSearchRoutes(t *testing.T) { So(string(resp.Body()), ShouldContainSubstring, repoName) So(string(resp.Body()), ShouldNotContainSubstring, inaccessibleRepo) - resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -10063,7 +10063,7 @@ func TestSearchRoutes(t *testing.T) { } // authenticated, but no access to resource - resp, err = resty.R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + + resp, err = resty.New().R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -10151,7 +10151,7 @@ func TestSearchRoutes(t *testing.T) { } } }` - resp, err := resty.R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + + resp, err := resty.New().R().SetBasicAuth(user1, password1).Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) @@ -10534,7 +10534,7 @@ func TestDistSpecExtensions(t *testing.T) { var extensionList distext.ExtensionList - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -10585,7 +10585,7 @@ func TestDistSpecExtensions(t *testing.T) { var extensionList distext.ExtensionList - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -10632,7 +10632,7 @@ func TestDistSpecExtensions(t *testing.T) { var extensionList distext.ExtensionList - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -10666,7 +10666,7 @@ func TestDistSpecExtensions(t *testing.T) { var extensionList distext.ExtensionList - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -10704,7 +10704,7 @@ func TestHTTPOptionsResponse(t *testing.T) { ctrlManager.StartAndWait(port) - resp, _ := resty.R().Options(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix) + resp, _ := resty.New().R().Options(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -10879,7 +10879,7 @@ func RunAuthorizationWithMultiplePoliciesTests(t *testing.T, userClient *resty.C digest := godigest.FromBytes(blob).String() // unauthenticated clients should not have access to /v2/, no policy is applied since none exists - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 401) @@ -10889,13 +10889,13 @@ func RunAuthorizationWithMultiplePoliciesTests(t *testing.T, userClient *resty.C conf.HTTP.AccessControl.Repositories[test.AuthorizationAllRepos] = repoPolicy // should have access to /v2/, anonymous policy is applied, "read" allowed - resp, err = resty.R().Get(baseURL + "/v2/") + resp, err = resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // with empty username:password - resp, err = resty.R().SetHeader("Authorization", "Basic Og==").Get(baseURL + "/v2/") + resp, err = resty.New().R().SetHeader("Authorization", "Basic Og==").Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -10950,7 +10950,7 @@ func RunAuthorizationWithMultiplePoliciesTests(t *testing.T, userClient *resty.C So(resp.StatusCode(), ShouldEqual, http.StatusOK) // get tags with anonymous read access should be ok - resp, err = resty.R().Get(baseURL + "/v2/" + AuthorizationNamespace + "/tags/list") + resp, err = resty.New().R().Get(baseURL + "/v2/" + AuthorizationNamespace + "/tags/list") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -10972,7 +10972,7 @@ func RunAuthorizationWithMultiplePoliciesTests(t *testing.T, userClient *resty.C So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -11008,7 +11008,7 @@ func RunAuthorizationWithMultiplePoliciesTests(t *testing.T, userClient *resty.C conf.HTTP.AccessControl.Repositories[test.AuthorizationAllRepos] = config.PolicyGroup{} // no policies, so no anonymous allowed - resp, err = resty.R().Get(baseURL + "/v2/_catalog") + resp, err = resty.New().R().Get(baseURL + "/v2/_catalog") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -11042,7 +11042,7 @@ func RunAuthorizationTests(t *testing.T, client *resty.Client, baseURL, user str digest := godigest.FromBytes(blob).String() // unauthenticated clients should not have access to /v2/ - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 401) diff --git a/pkg/cli/client/image_cmd_test.go b/pkg/cli/client/image_cmd_test.go index 3e1f5dbad..9ca3aebcd 100644 --- a/pkg/cli/client/image_cmd_test.go +++ b/pkg/cli/client/image_cmd_test.go @@ -1142,12 +1142,12 @@ func uploadTestMultiarch(baseURL string) { func uploadManifest(url string) error { // create and upload a blob/layer - resp, _ := resty.R().Post(url + "/v2/repo7/blobs/uploads/") + resp, _ := resty.New().R().Post(url + "/v2/repo7/blobs/uploads/") loc := test.Location(url, resp) content := []byte("this is a blob5") digest := godigest.FromBytes(content) - _, _ = resty.R().SetQueryParam("digest", digest.String()). + _, _ = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) // create config @@ -1174,10 +1174,10 @@ func uploadManifest(url string) error { cdigest := godigest.FromBytes(cblob) // upload image config blob - resp, _ = resty.R().Post(url + "/v2/repo7/blobs/uploads/") + resp, _ = resty.New().R().Post(url + "/v2/repo7/blobs/uploads/") loc = test.Location(url, resp) - _, _ = resty.R(). + _, _ = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -1207,7 +1207,7 @@ func uploadManifest(url string) error { return err } - _, _ = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + _, _ = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(url + "/v2/repo7/manifests/test:1.0") content = []byte("this is a blob5") @@ -1233,7 +1233,7 @@ func uploadManifest(url string) error { if err != nil { return err } - _, _ = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + _, _ = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(url + "/v2/repo7/manifests/test:2.0") return nil @@ -1241,7 +1241,7 @@ func uploadManifest(url string) error { func uploadManifestDerivedBase(url string) error { // create a blob/layer - _, _ = resty.R().Post(url + "/v2/repo7/blobs/uploads/") + _, _ = resty.New().R().Post(url + "/v2/repo7/blobs/uploads/") content1 := []byte("this is a blob5.0") content2 := []byte("this is a blob5.1") @@ -1249,11 +1249,11 @@ func uploadManifestDerivedBase(url string) error { digest1 := godigest.FromBytes(content1) digest2 := godigest.FromBytes(content2) digest3 := godigest.FromBytes(content3) - _, _ = resty.R().SetQueryParam("digest", digest1.String()). + _, _ = resty.New().R().SetQueryParam("digest", digest1.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content1).Post(url + "/v2/repo7/blobs/uploads/") - _, _ = resty.R().SetQueryParam("digest", digest2.String()). + _, _ = resty.New().R().SetQueryParam("digest", digest2.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content2).Post(url + "/v2/repo7/blobs/uploads/") - _, _ = resty.R().SetQueryParam("digest", digest3.String()). + _, _ = resty.New().R().SetQueryParam("digest", digest3.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content3).Post(url + "/v2/repo7/blobs/uploads/") // create config @@ -1280,10 +1280,10 @@ func uploadManifestDerivedBase(url string) error { cdigest := godigest.FromBytes(cblob) // upload image config blob - resp, _ := resty.R().Post(url + "/v2/repo7/blobs/uploads/") + resp, _ := resty.New().R().Post(url + "/v2/repo7/blobs/uploads/") loc := test.Location(url, resp) - _, _ = resty.R(). + _, _ = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -1321,7 +1321,7 @@ func uploadManifestDerivedBase(url string) error { return err } - _, _ = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + _, _ = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(url + "/v2/repo7/manifests/test:1.0") content1 = []byte("this is a blob5.0") @@ -1347,7 +1347,7 @@ func uploadManifestDerivedBase(url string) error { if err != nil { return err } - _, _ = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + _, _ = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(url + "/v2/repo7/manifests/test:2.0") return nil diff --git a/pkg/cli/server/extensions_test.go b/pkg/cli/server/extensions_test.go index 4df48cad4..bd37ba81e 100644 --- a/pkg/cli/server/extensions_test.go +++ b/pkg/cli/server/extensions_test.go @@ -524,7 +524,7 @@ func testWithMetricsEnabled(t *testing.T, rootDir string, cfgContentFormat strin }() WaitTillServerReady(baseURL) - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -664,7 +664,7 @@ func TestServeMetricsExtension(t *testing.T) { WaitTillServerReady(baseURL) - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) diff --git a/pkg/compliance/v1_0_0/check.go b/pkg/compliance/v1_0_0/check.go index 2fab2342c..9ad8de5ee 100644 --- a/pkg/compliance/v1_0_0/check.go +++ b/pkg/compliance/v1_0_0/check.go @@ -50,14 +50,14 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Make API calls to the controller", t, func(c C) { Convey("Check version", func() { _, _ = Print("\nCheck version") - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + "/") + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + "/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) Convey("Get repository catalog", func() { _, _ = Print("\nGet repository catalog") - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.String(), ShouldNotBeEmpty) @@ -69,16 +69,16 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(len(repoList.Repositories), ShouldEqual, 0) // after newly created upload should succeed - resp, err = resty.R().Post(baseURL + "/v2/z/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/z/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // after newly created upload should succeed - resp, err = resty.R().Post(baseURL + "/v2/a/b/c/d/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/a/b/c/d/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().SetResult(&api.RepositoryList{}).Get(baseURL + + resp, err = resty.New().R().SetResult(&api.RepositoryList{}).Get(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -97,17 +97,17 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Get images in a repository", func() { _, _ = Print("\nGet images in a repository") // non-existent repository should fail - resp, err := resty.R().Get(baseURL + "/v2/repo1/tags/list") + resp, err := resty.New().R().Get(baseURL + "/v2/repo1/tags/list") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.String(), ShouldNotBeEmpty) // after newly created upload should succeed - resp, err = resty.R().Post(baseURL + "/v2/repo1/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/repo1/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Get(baseURL + "/v2/repo1/tags/list") + resp, err = resty.New().R().Get(baseURL + "/v2/repo1/tags/list") So(err, ShouldBeNil) if !config.Compliance { @@ -119,17 +119,17 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Monolithic blob upload", func() { _, _ = Print("\nMonolithic blob upload") - resp, err := resty.R().Post(baseURL + "/v2/repo2/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo2/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) So(loc, ShouldNotBeEmpty) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) - resp, err = resty.R().Get(baseURL + "/v2/repo2/tags/list") + resp, err = resty.New().R().Get(baseURL + "/v2/repo2/tags/list") So(err, ShouldBeNil) if !config.Compliance { @@ -143,20 +143,20 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().Put(loc) + resp, err = resty.New().R().Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without the Content-Length should fail - resp, err = resty.R().SetQueryParam("digest", digest.String()).Put(loc) + resp, err = resty.New().R().SetQueryParam("digest", digest.String()).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without any data to send, should fail - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // monolithic blob upload: success - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -165,11 +165,11 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get("Content-Length"), ShouldEqual, "0") So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // upload reference should now be removed - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // blob reference should be accessible - resp, err = resty.R().Get(blobLoc) + resp, err = resty.New().R().Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -181,7 +181,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) // setting invalid URL params should fail - resp, err := resty.R(). + resp, err := resty.New().R(). SetQueryParam("digest", digest.String()). SetQueryParam("from", digest.String()). SetHeader("Content-Type", "application/octet-stream"). @@ -190,14 +190,14 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusMethodNotAllowed) // setting a "?digest=<>" but without body should fail - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream"). Post(baseURL + "/v2/repo2/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // set a "?digest=<>" - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream"). SetBody(content). @@ -207,24 +207,24 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { loc := test.Location(baseURL, resp) So(loc, ShouldNotBeEmpty) // blob reference should be accessible - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) Convey("Monolithic blob upload with multiple name components", func() { _, _ = Print("\nMonolithic blob upload with multiple name components") - resp, err := resty.R().Post(baseURL + "/v2/repo10/repo20/repo30/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo10/repo20/repo30/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) So(loc, ShouldNotBeEmpty) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) - resp, err = resty.R().Get(baseURL + "/v2/repo10/repo20/repo30/tags/list") + resp, err = resty.New().R().Get(baseURL + "/v2/repo10/repo20/repo30/tags/list") So(err, ShouldBeNil) if !config.Compliance { @@ -238,20 +238,20 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) - resp, err = resty.R().Put(loc) + resp, err = resty.New().R().Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without the Content-Length should fail - resp, err = resty.R().SetQueryParam("digest", digest.String()).Put(loc) + resp, err = resty.New().R().SetQueryParam("digest", digest.String()).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // without any data to send, should fail - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) // monolithic blob upload: success - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -260,18 +260,18 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get("Content-Length"), ShouldEqual, "0") So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // upload reference should now be removed - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // blob reference should be accessible - resp, err = resty.R().Get(blobLoc) + resp, err = resty.New().R().Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) Convey("Chunked blob upload", func() { _, _ = Print("\nChunked blob upload") - resp, err := resty.R().Post(baseURL + "/v2/repo3/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo3/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -286,13 +286,13 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write first chunk contentRange := fmt.Sprintf("%d-%d", 0, len(chunk1)-1) - resp, err = resty.R().SetHeader("Content-Type", "application/octet-stream"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/octet-stream"). SetHeader("Content-Range", contentRange).SetBody(chunk1).Patch(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // check progress - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) r := resp.Header().Get("Range") @@ -301,7 +301,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write same chunk should fail contentRange = fmt.Sprintf("%d-%d", 0, len(chunk1)-1) - resp, err = resty.R().SetHeader("Content-Type", "application/octet-stream"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/octet-stream"). SetHeader("Content-Range", contentRange).SetBody(chunk1).Patch(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) @@ -317,7 +317,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write final chunk contentRange = fmt.Sprintf("%d-%d", len(chunk1), len(buf.Bytes())-1) - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Range", contentRange). SetHeader("Content-Type", "application/octet-stream").SetBody(chunk2).Put(loc) So(err, ShouldBeNil) @@ -330,18 +330,18 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get("Content-Length"), ShouldEqual, "0") So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // upload reference should now be removed - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // blob reference should be accessible - resp, err = resty.R().Get(blobLoc) + resp, err = resty.New().R().Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) Convey("Chunked blob upload with multiple name components", func() { _, _ = Print("\nChunked blob upload with multiple name components") - resp, err := resty.R().Post(baseURL + "/v2/repo40/repo50/repo60/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo40/repo50/repo60/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -356,13 +356,13 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write first chunk contentRange := fmt.Sprintf("%d-%d", 0, len(chunk1)-1) - resp, err = resty.R().SetHeader("Content-Type", "application/octet-stream"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/octet-stream"). SetHeader("Content-Range", contentRange).SetBody(chunk1).Patch(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // check progress - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) r := resp.Header().Get("Range") @@ -371,7 +371,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write same chunk should fail contentRange = fmt.Sprintf("%d-%d", 0, len(chunk1)-1) - resp, err = resty.R().SetHeader("Content-Type", "application/octet-stream"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/octet-stream"). SetHeader("Content-Range", contentRange).SetBody(chunk1).Patch(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusRequestedRangeNotSatisfiable) @@ -387,7 +387,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // write final chunk contentRange = fmt.Sprintf("%d-%d", len(chunk1), len(buf.Bytes())-1) - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Range", contentRange). SetHeader("Content-Type", "application/octet-stream").SetBody(chunk2).Put(loc) So(err, ShouldBeNil) @@ -400,11 +400,11 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get("Content-Length"), ShouldEqual, "0") So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // upload reference should now be removed - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // blob reference should be accessible - resp, err = resty.R().Get(blobLoc) + resp, err = resty.New().R().Get(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -412,14 +412,14 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Create and delete uploads", func() { _, _ = Print("\nCreate and delete uploads") // create a upload - resp, err := resty.R().Post(baseURL + "/v2/repo4/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo4/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) So(loc, ShouldNotBeEmpty) // delete this upload - resp, err = resty.R().Delete(loc) + resp, err = resty.New().R().Delete(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) }) @@ -427,7 +427,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Create and delete blobs", func() { _, _ = Print("\nCreate and delete blobs") // create a upload - resp, err := resty.R().Post(baseURL + "/v2/repo5/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo5/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -437,7 +437,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) // monolithic blob upload - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -446,7 +446,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // delete this blob - resp, err = resty.R().Delete(blobLoc) + resp, err = resty.New().R().Delete(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) So(resp.Header().Get("Content-Length"), ShouldEqual, "0") @@ -455,7 +455,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Mount blobs", func() { _, _ = Print("\nMount blobs from another repository") // create a upload - resp, err := resty.R().Post(baseURL + "/v2/repo6/blobs/uploads/?digest=\"abc\"&&from=\"xyz\"") + resp, err := resty.New().R().Post(baseURL + "/v2/repo6/blobs/uploads/?digest=\"abc\"&&from=\"xyz\"") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldBeIn, []int{http.StatusCreated, http.StatusAccepted, http.StatusMethodNotAllowed}) }) @@ -463,7 +463,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Manifests", func() { _, _ = Print("\nManifests") // create a blob/layer - resp, err := resty.R().Post(baseURL + "/v2/repo7/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repo7/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -474,7 +474,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { _, err = os.Stat(path.Join(storageInfo[0], "repo7")) So(err, ShouldBeNil) - resp, err = resty.R().Get(loc) + resp, err = resty.New().R().Get(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -482,7 +482,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) // monolithic blob upload: success - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -492,7 +492,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // check a non-existent manifest - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Head(baseURL + "/v2/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -511,61 +511,61 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // delete manifest by tag should pass - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete manifest by digest (1.0 deleted but 1.0.1 has same reference) - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete manifest by digest - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // delete again should fail - resp, err = resty.R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:2.0") + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:2.0") + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) @@ -584,31 +584,31 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) } - resp, err := resty.R().Get(baseURL + "/v2/page0/tags/list") + resp, err := resty.New().R().Get(baseURL + "/v2/page0/tags/list") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n= ") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n= ") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n=a") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n=a") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n=0") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n=0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n=0&last=100") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n=0&last=100") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n=0&last=test:0.0") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n=0&last=test:0.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/page0/tags/list?n=3") + resp, err = resty.New().R().Get(baseURL + "/v2/page0/tags/list?n=3") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) next := resp.Header().Get("Link") @@ -625,7 +625,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { nextURL = baseURL + nextURL - resp, err = resty.R().Get(nextURL) + resp, err = resty.New().R().Get(nextURL) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) next = resp.Header().Get("Link") @@ -636,10 +636,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Repository names", func() { _, _ = Print("\nRepository names") // create a blob/layer - resp, err := resty.R().Post(baseURL + "/v2/repotest/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/repotest/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Post(baseURL + "/v2/repotest123/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/repotest123/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) }) @@ -647,13 +647,13 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { Convey("Multiple Storage", func() { // test APIS on subpath routes, default storage already tested above // subpath route firsttest - resp, err := resty.R().Post(baseURL + "/v2/firsttest/first/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/firsttest/first/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) firstloc := test.Location(baseURL, resp) So(firstloc, ShouldNotBeEmpty) - resp, err = resty.R().Get(firstloc) + resp, err = resty.New().R().Get(firstloc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -662,13 +662,13 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) // subpath route secondtest - resp, err = resty.R().Post(baseURL + "/v2/secondtest/second/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/secondtest/second/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) secondloc := test.Location(baseURL, resp) So(secondloc, ShouldNotBeEmpty) - resp, err = resty.R().Get(secondloc) + resp, err = resty.New().R().Get(secondloc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -681,7 +681,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(digest, ShouldNotBeNil) // monolithic blob upload: success // first test - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(firstloc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -691,7 +691,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // second test - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(secondloc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -701,17 +701,17 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty) // check a non-existent manifest - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Head(baseURL + "/v2/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Head(baseURL + "/v2/firsttest/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Head(baseURL + "/v2/secondtest/unknown/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -736,111 +736,111 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/firsttest/first/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/firsttest/first/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/firsttest/first/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/firsttest/first/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/secondtest/second/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/secondtest/second/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/secondtest/second/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/secondtest/second/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(resp.Body(), ShouldNotBeEmpty) // delete manifest by digest - resp, err = resty.R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // delete manifest by digest - resp, err = resty.R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // delete again should fail - resp, err = resty.R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Delete(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) // check/get by tag - resp, err = resty.R().Head(baseURL + "/v2/firsttest/first/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/firsttest/first/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/firsttest/first/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/firsttest/first/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/secondtest/second/manifests/test:1.0") + resp, err = resty.New().R().Head(baseURL + "/v2/secondtest/second/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/secondtest/second/manifests/test:1.0") + resp, err = resty.New().R().Get(baseURL + "/v2/secondtest/second/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/firsttest/first/repo7/manifests/test:2.0") + resp, err = resty.New().R().Head(baseURL + "/v2/firsttest/first/repo7/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/firsttest/first/manifests/test:2.0") + resp, err = resty.New().R().Get(baseURL + "/v2/firsttest/first/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/secondtest/second/manifests/test:2.0") + resp, err = resty.New().R().Head(baseURL + "/v2/secondtest/second/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/secondtest/second/manifests/test:2.0") + resp, err = resty.New().R().Get(baseURL + "/v2/secondtest/second/manifests/test:2.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) // check/get by reference - resp, err = resty.R().Head(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/firsttest/first/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) - resp, err = resty.R().Head(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Head(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - resp, err = resty.R().Get(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/secondtest/second/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.Body(), ShouldNotBeEmpty) diff --git a/pkg/compliance/v1_0_0/check_test.go b/pkg/compliance/v1_0_0/check_test.go index 069da5812..0758fe316 100644 --- a/pkg/compliance/v1_0_0/check_test.go +++ b/pkg/compliance/v1_0_0/check_test.go @@ -93,7 +93,7 @@ func startServer(t *testing.T) (*api.Controller, string) { for { // poll until ready - resp, _ := resty.R().Get(baseURL) + resp, _ := resty.New().R().Get(baseURL) if resp.StatusCode() == http.StatusNotFound { break } diff --git a/pkg/debug/pprof/pprof_test.go b/pkg/debug/pprof/pprof_test.go index f9574ef40..588aa0afa 100644 --- a/pkg/debug/pprof/pprof_test.go +++ b/pkg/debug/pprof/pprof_test.go @@ -46,30 +46,30 @@ func TestProfilingAuthz(t *testing.T) { defer cm.StopServer() // unauthenticated clients should have access to /v2/ - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // unauthenticated clients should have access to the profiling endpoints - resp, err = resty.R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") + resp, err = resty.New().R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetQueryParam("seconds", "1"). + resp, err = resty.New().R().SetQueryParam("seconds", "1"). Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "profile") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "goroutine") + resp, err = resty.New().R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "goroutine") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // test building the index - resp, err = resty.R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint) + resp, err = resty.New().R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -109,26 +109,26 @@ func TestProfilingAuthz(t *testing.T) { defer cm.StopServer() // unauthenticated clients should not have access to /v2/ - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // unauthenticated clients should not have access to the profiling endpoint - resp, err = resty.R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") + resp, err = resty.New().R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // authenticated clients without permissions should not have access to the profiling endpoint - resp, err = resty.R().SetBasicAuth(username, password). + resp, err = resty.New().R().SetBasicAuth(username, password). Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusForbidden) // authenticated clients with admin permissions should have access to the profiling endpoint - resp, err = resty.R().SetBasicAuth(adminUsername, adminPassword). + resp, err = resty.New().R().SetBasicAuth(adminUsername, adminPassword). Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) @@ -167,26 +167,26 @@ func TestProfilingAuthz(t *testing.T) { defer cm.StopServer() // unauthenticated clients should have access to /v2/ - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // unauthenticated clients should not have access to the profiling endpoint - resp, err = resty.R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") + resp, err = resty.New().R().Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // authenticated clients without permissions should not have access to the profiling endpoint - resp, err = resty.R().SetBasicAuth(username, password). + resp, err = resty.New().R().SetBasicAuth(username, password). Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusForbidden) // authenticated clients with admin permissions should have access to the profiling endpoint - resp, err = resty.R().SetBasicAuth(adminUsername, adminPassword). + resp, err = resty.New().R().SetBasicAuth(adminUsername, adminPassword). Get(baseURL + constants.RoutePrefix + debugConstants.ProfilingEndpoint + "trace") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) diff --git a/pkg/exporter/api/controller_test.go b/pkg/exporter/api/controller_test.go index 6cb273e8d..9aa0b4340 100644 --- a/pkg/exporter/api/controller_test.go +++ b/pkg/exporter/api/controller_test.go @@ -160,7 +160,7 @@ func TestNewExporter(t *testing.T) { }(serverController) // wait till ready for { - _, err := resty.R().Get(baseURL) + _, err := resty.New().R().Get(baseURL) if err == nil { break } @@ -169,7 +169,7 @@ func TestNewExporter(t *testing.T) { } // Side effect of calling this endpoint is that it will enable metrics - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) diff --git a/pkg/extensions/extension_image_trust_test.go b/pkg/extensions/extension_image_trust_test.go index d4f591f5b..d02f4e98a 100644 --- a/pkg/extensions/extension_image_trust_test.go +++ b/pkg/extensions/extension_image_trust_test.go @@ -103,12 +103,12 @@ func TestSignaturesAllowedMethodsHeader(t *testing.T) { ctrlManager.StartAndWait(port) defer ctrlManager.StopServer() - resp, _ := resty.R().Options(baseURL + constants.FullCosign) + resp, _ := resty.New().R().Options(baseURL + constants.FullCosign) So(resp, ShouldNotBeNil) So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "POST,OPTIONS") So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) - resp, _ = resty.R().Options(baseURL + constants.FullNotation) + resp, _ = resty.New().R().Options(baseURL + constants.FullNotation) So(resp, ShouldNotBeNil) So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "POST,OPTIONS") So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) @@ -456,7 +456,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[ gqlTargetURL := fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) // Verify the image is initially shown as not being signed - resp, err := resty.R().Get(gqlTargetURL) + resp, err := resty.New().R().Get(gqlTargetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -515,7 +515,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[ So(found, ShouldBeTrue) // verify the image is shown as signed and trusted - resp, err = resty.R().Get(gqlTargetURL) + resp, err = resty.New().R().Get(gqlTargetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -619,7 +619,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[ gqlTargetURL := fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) // Verify the image is initially shown as not being signed - resp, err := resty.R().Get(gqlTargetURL) + resp, err := resty.New().R().Get(gqlTargetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -686,7 +686,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[ So(found, ShouldBeTrue) // verify the image is shown as signed and trusted - resp, err = resty.R().Get(gqlTargetURL) + resp, err = resty.New().R().Get(gqlTargetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -903,7 +903,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[ So(found, ShouldBeTrue) // verify the image is shown as signed and trusted - resp, err := resty.R().Get(gqlTargetURL) + resp, err := resty.New().R().Get(gqlTargetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) diff --git a/pkg/extensions/extension_ui_test.go b/pkg/extensions/extension_ui_test.go index f48af6200..09063d22d 100644 --- a/pkg/extensions/extension_ui_test.go +++ b/pkg/extensions/extension_ui_test.go @@ -68,32 +68,32 @@ func TestUIExtension(t *testing.T) { err = UploadImage(image, baseURL, repoName, tagName) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + "/home") + resp, err := resty.New().R().Get(baseURL + "/home") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/image/") + resp, err = resty.New().R().Get(baseURL + "/image/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/image/" + repoName) + resp, err = resty.New().R().Get(baseURL + "/image/" + repoName) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/image/" + repoName + "/tag/") + resp, err = resty.New().R().Get(baseURL + "/image/" + repoName + "/tag/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/image/" + repoName + "/tag/" + tagName) + resp, err = resty.New().R().Get(baseURL + "/image/" + repoName + "/tag/" + tagName) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/badurl/") + resp, err = resty.New().R().Get(baseURL + "/badurl/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) diff --git a/pkg/extensions/extension_userprefs_test.go b/pkg/extensions/extension_userprefs_test.go index 87c2a56e4..b974238f1 100644 --- a/pkg/extensions/extension_userprefs_test.go +++ b/pkg/extensions/extension_userprefs_test.go @@ -53,7 +53,7 @@ func TestAllowedMethodsHeaderUserPrefs(t *testing.T) { ctrlManager.StartAndWait(port) defer ctrlManager.StopServer() - resp, _ := resty.R().Options(baseURL + constants.FullUserPrefs) + resp, _ := resty.New().R().Options(baseURL + constants.FullUserPrefs) So(resp, ShouldNotBeNil) So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "PUT,OPTIONS") So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) diff --git a/pkg/extensions/extensions_test.go b/pkg/extensions/extensions_test.go index 01e1cccad..89eecf4b3 100644 --- a/pkg/extensions/extensions_test.go +++ b/pkg/extensions/extensions_test.go @@ -196,12 +196,12 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Patch(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Patch(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusMethodNotAllowed) // without credentials - resp, err = resty.R().Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -215,7 +215,7 @@ func TestMgmtExtension(t *testing.T) { So(mgmtResp.HTTP.Auth.APIKey, ShouldBeFalse) // with credentials - resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -229,7 +229,7 @@ func TestMgmtExtension(t *testing.T) { So(mgmtResp.HTTP.Auth.APIKey, ShouldBeFalse) // with wrong credentials - resp, err = resty.R().SetBasicAuth(username, "wrong").Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().SetBasicAuth(username, "wrong").Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) }) @@ -280,7 +280,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -345,7 +345,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -417,7 +417,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -431,7 +431,7 @@ func TestMgmtExtension(t *testing.T) { So(mgmtResp.HTTP.Auth.APIKey, ShouldBeFalse) // with credentials - resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -504,7 +504,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -520,7 +520,7 @@ func TestMgmtExtension(t *testing.T) { So(mgmtResp.HTTP.Auth.APIKey, ShouldBeFalse) // with credentials - resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -588,7 +588,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -648,7 +648,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -715,7 +715,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -789,7 +789,7 @@ func TestMgmtExtension(t *testing.T) { So(err, ShouldBeNil) // without credentials - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -835,7 +835,7 @@ func TestMgmtExtension(t *testing.T) { ctlrManager.StartAndWait(port) defer ctlrManager.StopServer() - resp, err := resty.R().Get(baseURL + constants.FullMgmt) + resp, err := resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -909,13 +909,13 @@ func TestMgmtWithBearer(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader := authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -928,26 +928,26 @@ func TestMgmtWithBearer(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetHeader("Authorization", + resp, err = resty.New().R().SetHeader("Authorization", "Bearer "+goodToken.AccessToken).Options(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) - resp, err = resty.R().Post(baseURL + "/v2/" + authorizedNamespace + "/blobs/uploads/") + resp, err = resty.New().R().Post(baseURL + "/v2/" + authorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -957,21 +957,21 @@ func TestMgmtWithBearer(t *testing.T) { err = json.Unmarshal(resp.Body(), &goodToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+goodToken.AccessToken). Post(baseURL + "/v2/" + authorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R(). + resp, err = resty.New().R(). Post(baseURL + "/v2/" + unauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -984,7 +984,7 @@ func TestMgmtWithBearer(t *testing.T) { err = json.Unmarshal(resp.Body(), &badToken) So(err, ShouldBeNil) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Authorization", "Bearer "+badToken.AccessToken). Post(baseURL + "/v2/" + unauthorizedNamespace + "/blobs/uploads/") So(err, ShouldBeNil) @@ -992,7 +992,7 @@ func TestMgmtWithBearer(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // test mgmt route - resp, err = resty.R().Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1007,7 +1007,7 @@ func TestMgmtWithBearer(t *testing.T) { So(mgmtResp.HTTP.Auth.LDAP, ShouldBeNil) So(mgmtResp.HTTP.Auth.APIKey, ShouldBeFalse) - resp, err = resty.R().SetBasicAuth("", "").Get(baseURL + constants.FullMgmt) + resp, err = resty.New().R().SetBasicAuth("", "").Get(baseURL + constants.FullMgmt) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1048,7 +1048,7 @@ func TestAllowedMethodsHeaderMgmt(t *testing.T) { ctrlManager.StartAndWait(port) defer ctrlManager.StopServer() - resp, _ := resty.R().Options(baseURL + constants.FullMgmt) + resp, _ := resty.New().R().Options(baseURL + constants.FullMgmt) So(resp, ShouldNotBeNil) So(resp.Header().Get("Access-Control-Allow-Methods"), ShouldResemble, "GET,OPTIONS") So(resp.StatusCode(), ShouldEqual, http.StatusNoContent) diff --git a/pkg/extensions/get_extensions_disabled_test.go b/pkg/extensions/get_extensions_disabled_test.go index 8492d8782..cc2b1d27c 100644 --- a/pkg/extensions/get_extensions_disabled_test.go +++ b/pkg/extensions/get_extensions_disabled_test.go @@ -50,7 +50,7 @@ func TestGetExensionsDisabled(t *testing.T) { var extensionList distext.ExtensionList - resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) + resp, err := resty.New().R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) diff --git a/pkg/extensions/lint/lint_test.go b/pkg/extensions/lint/lint_test.go index 1651fd432..8e2721d7e 100644 --- a/pkg/extensions/lint/lint_test.go +++ b/pkg/extensions/lint/lint_test.go @@ -55,7 +55,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -71,7 +71,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -103,7 +103,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -119,7 +119,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -151,7 +151,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -173,7 +173,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -205,7 +205,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -224,7 +224,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { configDigest := manifest.Config.Digest - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest)) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -249,12 +249,12 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { So(err, ShouldBeNil) // upload image config blob - resp, err = resty.R(). + resp, err = resty.New().R(). Post(baseURL + "/v2/zot-test/blobs/uploads/") So(err, ShouldBeNil) loc := test.Location(baseURL, resp) - _, err = resty.R(). + _, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(configContent))). SetHeader("Content-Type", "application/octet-stream"). @@ -263,7 +263,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { Put(loc) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestContent).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) @@ -295,7 +295,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -312,7 +312,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { configDigest := manifest.Config.Digest - resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest)) + resp, err = resty.New().R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest)) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -337,12 +337,12 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { So(err, ShouldBeNil) // upload image config blob - _, err = resty.R(). + _, err = resty.New().R(). Post(baseURL + "/v2/zot-test/blobs/uploads/") So(err, ShouldBeNil) loc := test.Location(baseURL, resp) - _, err = resty.R(). + _, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(configContent))). SetHeader("Content-Type", "application/octet-stream"). @@ -351,7 +351,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { Put(loc) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestContent).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -383,7 +383,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -404,7 +404,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) @@ -440,7 +440,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -463,7 +463,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) { content, err := json.Marshal(manifest) So(err, ShouldBeNil) - resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(baseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusCreated) diff --git a/pkg/extensions/monitoring/monitoring_test.go b/pkg/extensions/monitoring/monitoring_test.go index 88351c7aa..fbab31e70 100644 --- a/pkg/extensions/monitoring/monitoring_test.go +++ b/pkg/extensions/monitoring/monitoring_test.go @@ -71,7 +71,7 @@ func TestExtensionMetrics(t *testing.T) { monitoring.ObserveStorageLockLatency(ctlr.Metrics, time.Millisecond, rootDir, "RWLock") - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -105,7 +105,7 @@ func TestExtensionMetrics(t *testing.T) { So(ctlr.Metrics.IsEnabled(), ShouldBeFalse) - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -127,7 +127,7 @@ func TestMetricsAuthentication(t *testing.T) { defer cm.StopServer() // metrics endpoint not available - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -154,7 +154,7 @@ func TestMetricsAuthentication(t *testing.T) { defer cm.StopServer() // without auth set metrics endpoint is available - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -197,24 +197,24 @@ func TestMetricsAuthentication(t *testing.T) { defer cm.StopServer() // without credentials - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // with wrong credentials - resp, err = resty.R().SetBasicAuth("atacker", "wrongpassword").Get(baseURL + "/metrics") + resp, err = resty.New().R().SetBasicAuth("atacker", "wrongpassword").Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // authenticated users - resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + "/metrics") + resp, err = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().SetBasicAuth(metricsuser, metricspass).Get(baseURL + "/metrics") + resp, err = resty.New().R().SetBasicAuth(metricsuser, metricspass).Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -336,13 +336,13 @@ func TestMetricsAuthorization(t *testing.T) { defer cm.StopServer() // unauthenticated clients should not have access to /metrics - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // unauthenticated clients should not have access to /metrics - resp, err = resty.R().SetBasicAuth("hacker", "trywithwrongpass").Get(baseURL + "/metrics") + resp, err = resty.New().R().SetBasicAuth("hacker", "trywithwrongpass").Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -392,13 +392,13 @@ func TestMetricsAuthorization(t *testing.T) { defer cm.StopServer() // unauthenticated clients should not have access to /metrics - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) // unauthenticated clients should not have access to /metrics - resp, err = resty.R().SetBasicAuth("hacker", "trywithwrongpass").Get(baseURL + "/metrics") + resp, err = resty.New().R().SetBasicAuth("hacker", "trywithwrongpass").Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) @@ -492,7 +492,7 @@ func TestPopulateStorageMetrics(t *testing.T) { busyboxSize, err := monitoring.GetDirSize(path.Join(rootDir, "busybox")) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + "/metrics") + resp, err := resty.New().R().Get(baseURL + "/metrics") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) diff --git a/pkg/extensions/search/cve/cve_test.go b/pkg/extensions/search/cve/cve_test.go index 57a401846..fcdee9bf4 100644 --- a/pkg/extensions/search/cve/cve_test.go +++ b/pkg/extensions/search/cve/cve_test.go @@ -468,15 +468,15 @@ func TestCVESearchDisabled(t *testing.T) { defer ctrlManager.StopServer() - resp, _ := resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ := resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(string(resp.Body()), ShouldContainSubstring, "cve search is disabled") So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}") So(string(resp.Body()), ShouldContainSubstring, "cve search is disabled") So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + "randomId" + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + "randomId" + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(string(resp.Body()), ShouldContainSubstring, "cve search is disabled") So(resp.StatusCode(), ShouldEqual, 200) @@ -558,7 +558,7 @@ func TestCVESearch(t *testing.T) { defer ctrlManager.StopServer() // without creds, should get access error - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 401) @@ -568,7 +568,7 @@ func TestCVESearch(t *testing.T) { err = json.Unmarshal(resp.Body(), &apiError) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix) + resp, err = resty.New().R().Get(baseURL + constants.FullSearchPrefix) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 401) @@ -576,21 +576,21 @@ func TestCVESearch(t *testing.T) { So(err, ShouldBeNil) // with creds, should get expected status code - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 404) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix) + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) var cveResult CveResult contains := false - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") err = json.Unmarshal(resp.Body(), &cveResult) So(err, ShouldBeNil) @@ -604,7 +604,7 @@ func TestCVESearch(t *testing.T) { So(contains, ShouldBeTrue) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -614,7 +614,7 @@ func TestCVESearch(t *testing.T) { cveid := cveResult.ImgList.CVEResultForImage.CVEList[0].ID - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -623,7 +623,7 @@ func TestCVESearch(t *testing.T) { So(err, ShouldBeNil) So(len(imgListWithCVEFixed.Images), ShouldEqual, 0) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-cve-test\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-cve-test\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -631,11 +631,11 @@ func TestCVESearch(t *testing.T) { So(err, ShouldBeNil) So(len(imgListWithCVEFixed.Images), ShouldEqual, 0) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"b/zot-squashfs-test:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"b/zot-squashfs-test:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -644,108 +644,108 @@ func TestCVESearch(t *testing.T) { So(err, ShouldBeNil) So(len(cveSquashFSResult.ImgList.CVEResultForImage.CVEList), ShouldBeZeroValue) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noindex:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noindex:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noindex\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noindex\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-index:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-index:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-index\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-index\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noblobs:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noblobs:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noblob\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noblob\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-test\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-test\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-blob:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-blob:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-blob\"){Results{RepoName%20LastUpdated}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-blob\"){Results{RepoName%20LastUpdated}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"cntos\"){Tag%20CVEList{Id%20Description%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"cntos\"){Tag%20CVEList{Id%20Description%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) // Testing Invalid Search URL - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Ta%20CVEList{Id%20Description%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Ta%20CVEList{Id%20Description%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(tet:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(tet:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageistForCVE(id:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageistForCVE(id:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-2018-20482\"){ame%20Tags}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-2018-20482\"){ame%20Tags}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(reo:\"zot-test:1.0.0\"){Tag%20CVEList{Id%20Description%20Severity}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(reo:\"zot-test:1.0.0\"){Tag%20CVEList{Id%20Description%20Severity}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 422) - resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"" + cveid + "\"){Results{RepoName%20Tag}}}") + resp, _ = resty.New().R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"" + cveid + "\"){Results{RepoName%20Tag}}}") So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) }) @@ -1820,7 +1820,7 @@ func TestFixedTagsWithIndex(t *testing.T) { } }` - resp, _ := resty.R().Get(baseURL + constants.FullSearchPrefix + "?query=" + + resp, _ := resty.New().R().Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(fmt.Sprintf(query, Vulnerability1ID, "repo"))) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) diff --git a/pkg/extensions/search/digest_test.go b/pkg/extensions/search/digest_test.go index 5bae1bec6..1155ee062 100644 --- a/pkg/extensions/search/digest_test.go +++ b/pkg/extensions/search/digest_test.go @@ -113,12 +113,12 @@ func TestDigestSearchHTTP(t *testing.T) { configDigest := godigest.FromBytes(configBlob) - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix) + resp, err = resty.New().R().Get(baseURL + constants.FullSearchPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -136,7 +136,7 @@ func TestDigestSearchHTTP(t *testing.T) { } } }` - resp, err = resty.R().Get( + resp, err = resty.New().R().Get( baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query), ) So(resp, ShouldNotBeNil) @@ -157,7 +157,7 @@ func TestDigestSearchHTTP(t *testing.T) { {Results{RepoName Tag Manifests {Digest ConfigDigest Size Layers { Digest }}}}}`) targetURL := baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(string(resp.Body()), ShouldNotBeNil) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -174,7 +174,7 @@ func TestDigestSearchHTTP(t *testing.T) { {Results{RepoName Tag Manifests {Digest ConfigDigest Size Layers { Digest }}}}}`) targetURL = baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -194,7 +194,7 @@ func TestDigestSearchHTTP(t *testing.T) { {Results{RepoName Tag Manifests {Digest ConfigDigest Size Layers { Digest }}}}}`) targetURL = baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery - resp, err = resty.R().Get( + resp, err = resty.New().R().Get( targetURL, ) @@ -225,7 +225,7 @@ func TestDigestSearchHTTP(t *testing.T) { } } }` - resp, err = resty.R().Get( + resp, err = resty.New().R().Get( baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query), ) So(resp, ShouldNotBeNil) @@ -244,7 +244,7 @@ func TestDigestSearchHTTP(t *testing.T) { RepoName Tag343s } }` - resp, err = resty.R().Get( + resp, err = resty.New().R().Get( baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query), ) So(resp, ShouldNotBeNil) @@ -297,12 +297,12 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) { err = UploadImage(image, baseURL, "a/zot-test", "0.0.1") So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix) + resp, err = resty.New().R().Get(baseURL + constants.FullSearchPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -318,7 +318,7 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) { } } }` - resp, err = resty.R().Get( + resp, err = resty.New().R().Get( baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query), ) So(resp, ShouldNotBeNil) @@ -353,12 +353,12 @@ func TestDigestSearchDisabled(t *testing.T) { // shut down server defer ctrlManager.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix) + resp, err = resty.New().R().Get(baseURL + constants.FullSearchPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 404) diff --git a/pkg/extensions/search/search_test.go b/pkg/extensions/search/search_test.go index 6a063eaea..aeb961350 100644 --- a/pkg/extensions/search/search_test.go +++ b/pkg/extensions/search/search_test.go @@ -392,12 +392,12 @@ func TestRepoListWithNewestImage(t *testing.T) { err = UploadImage(uploadedImage, baseURL, "a/zot-test", "0.0.1") So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -422,7 +422,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -456,7 +456,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -479,7 +479,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } } }}` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -507,7 +507,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -541,7 +541,7 @@ func TestRepoListWithNewestImage(t *testing.T) { }` // Verify we don't return any vulnerabilities if CVE scanning is disabled - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -571,7 +571,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -581,7 +581,7 @@ func TestRepoListWithNewestImage(t *testing.T) { panic(err) } - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -605,7 +605,7 @@ func TestRepoListWithNewestImage(t *testing.T) { panic(err) } - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -617,7 +617,7 @@ func TestRepoListWithNewestImage(t *testing.T) { panic(err) } - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -628,7 +628,7 @@ func TestRepoListWithNewestImage(t *testing.T) { panic(err) } - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -640,7 +640,7 @@ func TestRepoListWithNewestImage(t *testing.T) { panic(err) } - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -721,7 +721,7 @@ func TestRepoListWithNewestImage(t *testing.T) { WaitTillServerReady(baseURL) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -760,7 +760,7 @@ func TestRepoListWithNewestImage(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -894,7 +894,7 @@ func TestGetReferrersGQL(t *testing.T) { targetURL := fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err := resty.R().Get(targetURL) + resp, err := resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1022,7 +1022,7 @@ func TestGetReferrersGQL(t *testing.T) { targetURL := fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err := resty.R().Get(targetURL) + resp, err := resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1104,7 +1104,7 @@ func TestGetReferrersGQL(t *testing.T) { referrersQuery = fmt.Sprintf(referrersQuery, "repo", targetDigest.String()) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(referrersQuery)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(referrersQuery)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -1123,7 +1123,7 @@ func TestGetReferrersGQL(t *testing.T) { // Make REST call - resp, err = resty.R().Get(baseURL + "/v2/repo/referrers/" + targetDigest.String()) + resp, err = resty.New().R().Get(baseURL + "/v2/repo/referrers/" + targetDigest.String()) So(err, ShouldBeNil) var index ispec.Index @@ -1216,7 +1216,7 @@ func TestExpandedRepoInfo(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) responseStruct := &zcommon.ExpandedRepoInfoResp{} @@ -1282,12 +1282,12 @@ func TestExpandedRepoInfo(t *testing.T) { metrics := monitoring.NewMetricsServer(false, log) testStorage := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil) - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -1300,7 +1300,7 @@ func TestExpandedRepoInfo(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1325,7 +1325,7 @@ func TestExpandedRepoInfo(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1355,7 +1355,7 @@ func TestExpandedRepoInfo(t *testing.T) { err = signature.SignImageUsingCosign("zot-cve-test:0.0.1", port, false) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1387,7 +1387,7 @@ func TestExpandedRepoInfo(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1404,7 +1404,7 @@ func TestExpandedRepoInfo(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1432,7 +1432,7 @@ func TestExpandedRepoInfo(t *testing.T) { err = signature.SignImageUsingCosign("zot-test@"+testManifestDigest.String(), port, false) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "/query?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "/query?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1461,7 +1461,7 @@ func TestExpandedRepoInfo(t *testing.T) { err = os.Remove(path.Join(rootDir, "zot-test/blobs/sha256", manifestDigest.Encoded())) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1521,7 +1521,7 @@ func TestExpandedRepoInfo(t *testing.T) { } } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1567,12 +1567,12 @@ func TestExpandedRepoInfo(t *testing.T) { ctlrManager.StartAndWait(port) defer ctlrManager.StopServer() - resp, err := resty.R().Get(baseURL + "/v2/") + resp, err := resty.New().R().Get(baseURL + "/v2/") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 422) @@ -1606,7 +1606,7 @@ func TestExpandedRepoInfo(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -1715,7 +1715,7 @@ func TestExpandedRepoInfo(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -2046,7 +2046,7 @@ func TestDerivedImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(strings.Contains(string(resp.Body()), "same-layers"), ShouldBeFalse) //nolint:goconst So(strings.Contains(string(resp.Body()), "missing-layers"), ShouldBeFalse) @@ -2074,7 +2074,7 @@ func TestDerivedImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(strings.Contains(string(resp.Body()), "same-layers"), ShouldBeFalse) //nolint:goconst So(strings.Contains(string(resp.Body()), "missing-layers"), ShouldBeFalse) @@ -2103,7 +2103,7 @@ func TestDerivedImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(string(resp.Body()), ShouldContainSubstring, "repository not found") So(err, ShouldBeNil) }) @@ -2128,7 +2128,7 @@ func TestDerivedImageList(t *testing.T) { responseStruct := &zcommon.DerivedImageListResponse{} contains := false - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) err = json.Unmarshal(resp.Body(), responseStruct) @@ -2184,7 +2184,7 @@ func TestDerivedImageListNoRepos(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -2688,7 +2688,7 @@ func TestBaseImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(strings.Contains(string(resp.Body()), "less-layers"), ShouldBeTrue) So(strings.Contains(string(resp.Body()), "one-layer"), ShouldBeTrue) @@ -2719,7 +2719,7 @@ func TestBaseImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(strings.Contains(string(resp.Body()), "less-layers"), ShouldBeTrue) So(strings.Contains(string(resp.Body()), "one-layer"), ShouldBeFalse) @@ -2751,7 +2751,7 @@ func TestBaseImageList(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(string(resp.Body()), ShouldContainSubstring, "repository not found") So(err, ShouldBeNil) }) @@ -2776,7 +2776,7 @@ func TestBaseImageList(t *testing.T) { responseStruct := &zcommon.BaseImageListResponse{} contains := false - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) err = json.Unmarshal(resp.Body(), responseStruct) @@ -2833,7 +2833,7 @@ func TestBaseImageListNoRepos(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(strings.Contains(string(resp.Body()), "no reference provided"), ShouldBeTrue) So(err, ShouldBeNil) }) @@ -2909,7 +2909,7 @@ func TestGlobalSearchImageAuthor(t *testing.T) { } } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -2936,7 +2936,7 @@ func TestGlobalSearchImageAuthor(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -2964,7 +2964,7 @@ func TestGlobalSearchImageAuthor(t *testing.T) { } } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -2991,7 +2991,7 @@ func TestGlobalSearchImageAuthor(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -3208,7 +3208,7 @@ func TestGlobalSearch(t *testing.T) { Layers { Digest Size } } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -3304,7 +3304,7 @@ func TestGlobalSearch(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -3553,7 +3553,7 @@ func TestGlobalSearch(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -3661,7 +3661,7 @@ func TestGlobalSearch(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -3954,7 +3954,7 @@ func TestCleaningFilteringParamsGlobalSearch(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4008,7 +4008,7 @@ func TestGlobalSearchFiltering(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4055,7 +4055,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { } }`, longString) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4077,7 +4077,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { } }`, longString) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4099,7 +4099,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { } }`, longString) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4226,7 +4226,7 @@ func TestImageList(t *testing.T) { } }`, repos[0]) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) So(resp, ShouldNotBeNil) @@ -4263,7 +4263,7 @@ func TestImageList(t *testing.T) { } }`, repos[0], limit) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) So(resp, ShouldNotBeNil) @@ -4314,7 +4314,7 @@ func TestGlobalSearchPagination(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4341,7 +4341,7 @@ func TestGlobalSearchPagination(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4372,7 +4372,7 @@ func TestGlobalSearchPagination(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4405,7 +4405,7 @@ func TestGlobalSearchPagination(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4438,7 +4438,7 @@ func TestGlobalSearchPagination(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4544,7 +4544,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { err = signature.SignImageUsingCosign("repo1:1.0.1", port, false) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage1)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage1)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4557,7 +4557,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // check image 2 is signed also because it has the same manifest - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage2)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage2)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4570,13 +4570,13 @@ func TestMetaDBWhenSigningImages(t *testing.T) { So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // delete the signature - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + fmt.Sprintf("sha256-%s.sig", manifestDigest.Encoded())) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // check image 2 is not signed anymore - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage2)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage2)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4604,7 +4604,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { } // push bad manifest blob - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody([]byte("unmashable manifest blob")). Put(baseURL + "/v2/" + "repo" + "/manifests/" + "tag") @@ -4630,7 +4630,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { err = signature.SignImageUsingNotary("repo1:1.0.1", port, true) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage1)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage1)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4647,7 +4647,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { err = signature.SignImageUsingNotary("repo1:index", port, false) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryIndex)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryIndex)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -4664,7 +4664,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { err = signature.SignImageUsingCosign("repo1:index", port, false) So(err, ShouldBeNil) - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryIndex)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryIndex)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -4775,7 +4775,7 @@ func RunMetaDBIndexTests(baseURL, port string) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4793,7 +4793,7 @@ func RunMetaDBIndexTests(baseURL, port string) { err = signature.SignImageUsingCosign("repo@"+multiarchImage.DigestStr(), port, false) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4811,10 +4811,10 @@ func RunMetaDBIndexTests(baseURL, port string) { // remove signature cosignTag := "sha256-" + multiarchImage.Digest().Encoded() + ".sig" - _, err = resty.R().Delete(baseURL + "/v2/" + "repo" + "/manifests/" + cosignTag) + _, err = resty.New().R().Delete(baseURL + "/v2/" + "repo" + "/manifests/" + cosignTag) So(err, ShouldBeNil) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4938,7 +4938,7 @@ func RunMetaDBIndexTests(baseURL, port string) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -5016,7 +5016,7 @@ func RunMetaDBIndexTests(baseURL, port string) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape( fmt.Sprintf(query, baseLinuxAMD64Digest.String()), ), @@ -5027,7 +5027,7 @@ func RunMetaDBIndexTests(baseURL, port string) { So(strings.Contains(string(resp.Body()), "less-layers-linux-amd64"), ShouldEqual, true) So(strings.Contains(string(resp.Body()), "less-layers-linux-somearch"), ShouldEqual, false) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape( fmt.Sprintf(query, baseLinuxSomeArchDigest.String()), ), @@ -5150,7 +5150,7 @@ func RunMetaDBIndexTests(baseURL, port string) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -5232,7 +5232,7 @@ func RunMetaDBIndexTests(baseURL, port string) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape( fmt.Sprintf(query, baseLinuxAMD64Digest.String()), ), @@ -5243,7 +5243,7 @@ func RunMetaDBIndexTests(baseURL, port string) { So(strings.Contains(string(resp.Body()), "more-layers-linux-amd64"), ShouldEqual, true) So(strings.Contains(string(resp.Body()), "more-layers-linux-somearch"), ShouldEqual, false) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape( fmt.Sprintf(query, baseLinuxSomeArchDigest.String()), ), @@ -5282,15 +5282,15 @@ func TestMetaDBWhenReadingImages(t *testing.T) { So(err, ShouldBeNil) Convey("Download 3 times", func() { - resp, err := resty.R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") + resp, err = resty.New().R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") + resp, err = resty.New().R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5303,7 +5303,7 @@ func TestMetaDBWhenReadingImages(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5323,7 +5323,7 @@ func TestMetaDBWhenReadingImages(t *testing.T) { }, } - resp, err := resty.R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") + resp, err := resty.New().R().Get(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) }) @@ -5387,7 +5387,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5400,12 +5400,12 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { So(len(responseStruct.Images), ShouldEqual, 2) Convey("Delete a normal tag", func() { - resp, err := resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") + resp, err := resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5437,7 +5437,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5473,13 +5473,13 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { } // delete the signature using the digest - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + signatureTag) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + signatureTag) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // verify isSigned again and it should be false - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5511,7 +5511,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { }` // test if it's signed - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5569,13 +5569,13 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { So(sigManifestContent.Subject.Digest.String(), ShouldEqual, manifest1Digest.String()) // delete the signature using the digest - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + signatureReference) + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + signatureReference) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) // verify isSigned again and it should be false - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5610,7 +5610,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { } }`, image1.ManifestDescriptor.Digest.String()) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5632,7 +5632,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(statusCode, ShouldEqual, http.StatusAccepted) - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -5652,7 +5652,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { return []byte{}, "", "", zerr.ErrRepoNotFound }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) ctlr.StoreController.DefaultStore = mocks.MockedImageStore{ @@ -5660,7 +5660,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { return []byte{}, "", "", zerr.ErrBadManifest }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -5669,7 +5669,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { return []byte{}, "", "", zerr.ErrRepoNotFound }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) }) @@ -5686,7 +5686,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "signatureReference") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError) @@ -5715,7 +5715,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "sha256-343ebab94a7674da181c6ea3da013aee4f8cbe357870f8dcaf6268d5343c3474.sig") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -5752,7 +5752,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { }, } - resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + + resp, err = resty.New().R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "343ebab94a7674da181c6ea3da013aee4f8cbe357870f8dcaf6268d5343c3474.sig") So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -5817,7 +5817,7 @@ func TestSearchSize(t *testing.T) { } } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) @@ -5854,7 +5854,7 @@ func TestSearchSize(t *testing.T) { } } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) @@ -5896,7 +5896,7 @@ func TestSearchSize(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) @@ -5931,7 +5931,7 @@ func TestSearchSize(t *testing.T) { } }` - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) @@ -6069,7 +6069,7 @@ func TestImageSummary(t *testing.T) { targetURL = fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) contains := false - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -6093,7 +6093,7 @@ func TestImageSummary(t *testing.T) { strQuery = fmt.Sprintf(gqlQuery, repoName, tagTarget) targetURL = fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6141,7 +6141,7 @@ func TestImageSummary(t *testing.T) { strQuery = fmt.Sprintf(gqlQuery, "wrong-repo-does-not-exist", "latest") targetURL = fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6161,7 +6161,7 @@ func TestImageSummary(t *testing.T) { strQuery = fmt.Sprintf(gqlQuery, repoName, "nonexisttag") targetURL = fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6275,7 +6275,7 @@ func TestImageSummary(t *testing.T) { strQuery = fmt.Sprintf(gqlQuery, repoName, tagTarget) targetURL = fmt.Sprintf("%s%s", gqlEndpoint, url.QueryEscape(strQuery)) - resp, err = resty.R().Get(targetURL) + resp, err = resty.New().R().Get(targetURL) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6365,7 +6365,7 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) // GET image 1 - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImg1)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImg1)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6379,7 +6379,7 @@ func TestImageSummary(t *testing.T) { So(imgSum.Manifests[0].ArtifactType, ShouldResemble, artType1) // GET image 2 - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImg2)) + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImg2)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6408,7 +6408,7 @@ func TestImageSummary(t *testing.T) { var expandedRepoInfoResp zcommon.ExpandedRepoInfoResp - resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + + resp, err = resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryExpRepoInfo)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) @@ -6481,7 +6481,7 @@ func TestUploadingArtifactsWithDifferentMediaType(t *testing.T) { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -6864,7 +6864,7 @@ func GlobalSearchGQL(query, baseURL string) *zcommon.GlobalSearchResultResp { } }` - resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryStr)) + resp, err := resty.New().R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryStr)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) diff --git a/pkg/extensions/search/userprefs_test.go b/pkg/extensions/search/userprefs_test.go index ba4d0cf97..ce9ac8a65 100644 --- a/pkg/extensions/search/userprefs_test.go +++ b/pkg/extensions/search/userprefs_test.go @@ -129,7 +129,7 @@ func TestUserData(t *testing.T) { userprefsBaseURL := baseURL + constants.FullUserPrefs Convey("Flip starred repo authorized", func(c C) { - clientHTTP := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + clientHTTP := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userStaredReposQuery)) @@ -178,7 +178,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip starred repo unauthenticated user", func(c C) { - clientHTTP := resty.R() + clientHTTP := resty.New().R() resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userStaredReposQuery)) @@ -208,7 +208,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip starred repo unauthorized", func(c C) { - clientHTTP := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + clientHTTP := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userStaredReposQuery)) @@ -238,7 +238,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip starred repo with unauthorized repo and admin user", func(c C) { - clientHTTP := resty.R().SetBasicAuth(adminUser, adminPassword) + clientHTTP := resty.New().R().SetBasicAuth(adminUser, adminPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userStaredReposQuery)) @@ -287,7 +287,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip bookmark repo authorized", func(c C) { - clientHTTP := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + clientHTTP := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userBookmarkedReposQuery)) @@ -335,7 +335,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip bookmark repo unauthenticated user", func(c C) { - clientHTTP := resty.R() + clientHTTP := resty.New().R() resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userBookmarkedReposQuery)) @@ -365,7 +365,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip bookmark repo unauthorized", func(c C) { - clientHTTP := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + clientHTTP := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userBookmarkedReposQuery)) @@ -395,7 +395,7 @@ func TestUserData(t *testing.T) { }) Convey("Flip bookmarked unauthorized repo and admin user", func(c C) { - clientHTTP := resty.R().SetBasicAuth(adminUser, adminPassword) + clientHTTP := resty.New().R().SetBasicAuth(adminUser, adminPassword) resp, err := clientHTTP.Get(baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(userBookmarkedReposQuery)) @@ -543,8 +543,8 @@ func TestChangingRepoState(t *testing.T) { defer ctlrManager.StopServer() - simpleUserClient := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) - anonynousClient := resty.R() + simpleUserClient := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) + anonynousClient := resty.New().R() userprefsBaseURL := baseURL + constants.FullUserPrefs @@ -643,7 +643,7 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { defer ctlrManager.StopServer() preferencesBaseURL := baseURL + constants.FullUserPrefs - simpleUserClient := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + simpleUserClient := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) // ------ Add simple repo repo := "repo" @@ -838,7 +838,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { defer ctlrManager.StopServer() preferencesBaseURL := baseURL + constants.FullUserPrefs - simpleUserClient := resty.R().SetBasicAuth(simpleUser, simpleUserPassword) + simpleUserClient := resty.New().R().SetBasicAuth(simpleUser, simpleUserPassword) // ------ Add sbrepo and star/bookmark it sbrepo := "sbrepo" diff --git a/pkg/extensions/sync/sync_disabled_test.go b/pkg/extensions/sync/sync_disabled_test.go index dd9f5063c..a795516c6 100644 --- a/pkg/extensions/sync/sync_disabled_test.go +++ b/pkg/extensions/sync/sync_disabled_test.go @@ -48,13 +48,13 @@ func TestSyncExtension(t *testing.T) { Convey("verify sync is skipped when binary doesn't include it", func() { // image - resp, err := resty.R(). + resp, err := resty.New().R(). Head(baseURL + "/v2/" + "invalid" + "/manifests/invalid:0.0.2") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) // reference - resp, err = resty.R(). + resp, err = resty.New().R(). Head(baseURL + "/v2/" + "invalid" + "/manifests/sha256_digest.sig") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 6de762a3e..591f76209 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -533,7 +533,7 @@ func TestOnDemand(t *testing.T) { OCIRefManifestBlob, err := json.Marshal(OCIRefManifest) So(err, ShouldBeNil) - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). SetBody(OCIRefManifestBlob). Put(srcBaseURL + "/v2/remote-repo/manifests/oci.ref") @@ -624,7 +624,7 @@ func TestOnDemand(t *testing.T) { dcm.StartAndWait(destPort) defer dcm.StopServer() - resp, err = resty.R().Get(destBaseURL + "/v2/remote-repo/manifests/test") + resp, err = resty.New().R().Get(destBaseURL + "/v2/remote-repo/manifests/test") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -682,7 +682,7 @@ func TestOnDemand(t *testing.T) { tagRefIndexBlob, err := json.Marshal(tagRefIndex) So(err, ShouldBeNil) - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageIndex). SetBody(tagRefIndexBlob). Put(srcBaseURL + "/v2/remote-repo/manifests/" + tag) @@ -760,11 +760,11 @@ func TestOnDemand(t *testing.T) { dcm.StartAndWait(destPort) defer dcm.StopServer() - resp, err = resty.R().Get(destBaseURL + "/v2/remote-repo/manifests/test") + resp, err = resty.New().R().Get(destBaseURL + "/v2/remote-repo/manifests/test") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - resp, err = resty.R().Get(destBaseURL + "/v2/remote-repo/manifests/" + tag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/remote-repo/manifests/" + tag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -1118,7 +1118,7 @@ func TestSyncReferenceInLoop(t *testing.T) { // we will push references in loop: image A -> sbom A -> oci artifact A -> sbom A (same sbom as before) // recursive syncing it should not get in an infinite loop // sync testImage and get its digest - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1131,7 +1131,7 @@ func TestSyncReferenceInLoop(t *testing.T) { sbomTag := strings.Replace(imageDigest.String(), ":", "-", 1) + "." + remote.SBOMTagSuffix // sync sbom and get its digest - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, sbomTag)) So(err, ShouldBeNil) @@ -1172,7 +1172,7 @@ func TestSyncReferenceInLoop(t *testing.T) { OCIRefDigest := godigest.FromBytes(OCIRefManifestBlob) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). SetBody(OCIRefManifestBlob). Put(srcBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, OCIRefDigest)) @@ -1184,7 +1184,7 @@ func TestSyncReferenceInLoop(t *testing.T) { // can not use same function attachSBOM because its digest will differ sbomTag2 := strings.Replace(OCIRefDigest.String(), ":", "-", 1) + "." + remote.SBOMTagSuffix - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). SetBody(sbomManifestBuf). Put(srcBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, sbomTag2)) @@ -1193,27 +1193,27 @@ func TestSyncReferenceInLoop(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusCreated) // sync image - resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // check all references are synced // first sbom - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, sbomTag)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // oci ref - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, OCIRefDigest)) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // second sbom - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", testImage, sbomTag2)) So(err, ShouldBeNil) @@ -1396,12 +1396,12 @@ func TestDockerImagesAreSkipped(t *testing.T) { dcm.StartAndWait(dctlr.Config.HTTP.Port) defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // now it should be skipped - resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1428,7 +1428,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { err = os.Chmod(path.Join(srcDir, testImage, "blobs/sha256", configBlobDigest.Encoded()), 0o000) So(err, ShouldBeNil) - resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -1449,7 +1449,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { err := UploadMultiarchImage(multiarchImage, srcBaseURL, indexRepoName, "latest") So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(srcBaseURL + "/v2/index/manifests/latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1552,7 +1552,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { defer dcm.StopServer() // sync - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1560,7 +1560,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) // sync again, should skip - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -1590,7 +1590,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { err = os.Chmod(path.Join(srcDir, indexRepoName, "blobs/sha256", configBlobDigest.Encoded()), 0o000) So(err, ShouldBeNil) - resp, err = resty.R().Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -1982,7 +1982,7 @@ func TestPermsDenied(t *testing.T) { So(found, ShouldBeTrue) - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -2087,7 +2087,7 @@ func TestConfigReloader(t *testing.T) { // wait till ready for { - _, err := resty.R().Get(destBaseURL) + _, err := resty.New().R().Get(destBaseURL) if err == nil { break } @@ -2237,7 +2237,7 @@ func TestConfigReloader(t *testing.T) { // wait till ready for { - _, err := resty.R().Get(destBaseURL) + _, err := resty.New().R().Get(destBaseURL) if err == nil { break } @@ -2622,7 +2622,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader := authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). Get(authorizationHeader.Realm) So(err, ShouldBeNil) @@ -2647,7 +2647,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -2770,7 +2770,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader := authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). Get(authorizationHeader.Realm) So(err, ShouldBeNil) @@ -2795,7 +2795,7 @@ func TestBearerAuth(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized) authorizationHeader = authutils.ParseBearerAuthHeader(resp.Header().Get("WWW-Authenticate")) - resp, err = resty.R(). + resp, err = resty.New().R(). SetQueryParam("service", authorizationHeader.Service). SetQueryParam("scope", authorizationHeader.Scope). Get(authorizationHeader.Realm) @@ -3010,7 +3010,7 @@ func TestBasicAuth(t *testing.T) { So(found, ShouldBeTrue) - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -3378,14 +3378,14 @@ func TestNotSemver(t *testing.T) { defer scm.StopServer() // get manifest so we can update it with a semver non compliant tag - resp, err := resty.R().Get(srcBaseURL + "/v2/zot-test/manifests/0.0.1") + resp, err := resty.New().R().Get(srcBaseURL + "/v2/zot-test/manifests/0.0.1") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) manifestBlob := resp.Body() - resp, err = resty.R().SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestBlob). Put(srcBaseURL + "/v2/" + testImage + "/manifests/notSemverTag") So(err, ShouldBeNil) @@ -3818,7 +3818,7 @@ func TestSubPaths(t *testing.T) { var destTagsList TagsList for { - resp, err := resty.R().Get(destBaseURL + constants.RoutePrefix + path.Join(subpath, testImage) + "/tags/list") + resp, err := resty.New().R().Get(destBaseURL + constants.RoutePrefix + path.Join(subpath, testImage) + "/tags/list") if err != nil { panic(err) } @@ -3878,7 +3878,7 @@ func TestOnDemandRepoErr(t *testing.T) { defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -3931,7 +3931,7 @@ func TestOnDemandContentFiltering(t *testing.T) { defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -3971,7 +3971,7 @@ func TestOnDemandContentFiltering(t *testing.T) { dcm.StartAndWait(dctlr.Config.HTTP.Port) defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -4024,7 +4024,7 @@ func TestConfigRules(t *testing.T) { defer dcm.StopServer() // image should not be synced - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -4054,7 +4054,7 @@ func TestConfigRules(t *testing.T) { dcm.StartAndWait(dctlr.Config.HTTP.Port) defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -4081,7 +4081,7 @@ func TestConfigRules(t *testing.T) { dcm.StartAndWait(dctlr.Config.HTTP.Port) defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -4322,7 +4322,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { So(found, ShouldBeTrue) // should not be synced nor sync on demand - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) @@ -4333,7 +4333,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { "." + remote.SignatureTagSuffix getCosignManifestURL := srcBaseURL + path.Join(constants.RoutePrefix, repoName, "manifests", cosignTag) - mResp, err := resty.R().Get(getCosignManifestURL) + mResp, err := resty.New().R().Get(getCosignManifestURL) So(err, ShouldBeNil) var cm ispec.Manifest @@ -4370,7 +4370,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { So(found, ShouldBeTrue) // should not be synced nor sync on demand - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + cosignTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + cosignTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) @@ -4385,7 +4385,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { notaryURLPath := path.Join("/v2/", repoName, "referrers", imageManifestDigest.String()) // based on image manifest digest get referrers - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.notary.signature"). Get(srcBaseURL + notaryURLPath) @@ -4440,7 +4440,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { So(found, ShouldBeTrue) // should not be synced nor sync on demand - resp, err = resty.R().SetHeader("Content-Type", "application/json"). + resp, err = resty.New().R().SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.notary.signature"). Get(destBaseURL + notaryURLPath) So(err, ShouldBeNil) @@ -4458,7 +4458,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { artifactURLPath := path.Join("/v2", repoName, "referrers", imageManifestDigest.String()) // based on image manifest digest get referrers - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.icecream"). Get(srcBaseURL + artifactURLPath) @@ -4521,7 +4521,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { So(found, ShouldBeTrue) // should not be synced nor sync on demand - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.icecream"). Get(destBaseURL + artifactURLPath) @@ -4578,7 +4578,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) { So(found, ShouldBeTrue) // should not be synced nor sync on demand - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.icecream"). Get(destBaseURL + artifactURLPath) @@ -4689,7 +4689,7 @@ func TestSignatures(t *testing.T) { sbomTag := strings.Replace(digest.String(), ":", "-", 1) + "." + remote.SBOMTagSuffix // get sbom digest - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). Get(srcBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, sbomTag)) So(err, ShouldBeNil) @@ -4733,7 +4733,7 @@ func TestSignatures(t *testing.T) { ociRefDigest := godigest.FromBytes(OCIRefManifestBlob) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). SetBody(OCIRefManifestBlob). Put(srcBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, ociRefDigest.String())) @@ -4828,7 +4828,7 @@ func TestSignatures(t *testing.T) { // get oci references from downstream, should be synced getOCIReferrersURL := destBaseURL + path.Join("/v2", repoName, "referrers", digest.String()) - resp, err = resty.R().Get(getOCIReferrersURL) + resp, err = resty.New().R().Get(getOCIReferrersURL) So(err, ShouldBeNil) So(resp, ShouldNotBeEmpty) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4843,7 +4843,7 @@ func TestSignatures(t *testing.T) { // get cosign sbom sbomCosignTag := string(digest.Algorithm()) + "-" + digest.Encoded() + "." + remote.SBOMTagSuffix - resp, err = resty.R().Get(destBaseURL + path.Join("/v2/", repoName, "manifests", sbomCosignTag)) + resp, err = resty.New().R().Get(destBaseURL + path.Join("/v2/", repoName, "manifests", sbomCosignTag)) So(err, ShouldBeNil) So(resp, ShouldNotBeEmpty) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4870,7 +4870,7 @@ func TestSignatures(t *testing.T) { // get oci ref pointing to sbom getOCIReferrersURL = destBaseURL + path.Join("/v2", repoName, "referrers", sbomDigest.String()) - resp, err = resty.R().Get(getOCIReferrersURL) + resp, err = resty.New().R().Get(getOCIReferrersURL) So(err, ShouldBeNil) So(resp, ShouldNotBeEmpty) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4887,7 +4887,7 @@ func TestSignatures(t *testing.T) { // based on manifest digest get referrers getReferrersURL := srcBaseURL + path.Join("/v2/", repoName, "referrers", digest.String()) - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.notary.signature"). Get(getReferrersURL) @@ -4925,7 +4925,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4943,7 +4943,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4959,7 +4959,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4972,7 +4972,7 @@ func TestSignatures(t *testing.T) { cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig" getCosignManifestURL := srcBaseURL + path.Join(constants.RoutePrefix, repoName, "manifests", cosignEncodedDigest) - mResp, err := resty.R().Get(getCosignManifestURL) + mResp, err := resty.New().R().Get(getCosignManifestURL) So(err, ShouldBeNil) So(mResp.StatusCode(), ShouldEqual, http.StatusOK) @@ -4994,7 +4994,7 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5015,7 +5015,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5038,7 +5038,7 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5059,7 +5059,7 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5076,7 +5076,7 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5085,7 +5085,7 @@ func TestSignatures(t *testing.T) { getOCIReferrersURL = srcBaseURL + path.Join("/v2", repoName, "referrers", digest.String()) - resp, err = resty.R().Get(getOCIReferrersURL) + resp, err = resty.New().R().Get(getOCIReferrersURL) So(err, ShouldBeNil) So(resp, ShouldNotBeEmpty) @@ -5118,7 +5118,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5142,7 +5142,7 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5163,7 +5163,7 @@ func TestSignatures(t *testing.T) { } // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5172,12 +5172,12 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) // sync on demand again for coverage - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) }) @@ -5271,7 +5271,7 @@ func TestSignatures(t *testing.T) { // get oci references from downstream, should be synced getOCIReferrersURL := destBaseURL + path.Join("/v2", repoName, "referrers", digest.String()) - resp, err := resty.R().Get(getOCIReferrersURL) + resp, err := resty.New().R().Get(getOCIReferrersURL) So(err, ShouldBeNil) So(resp, ShouldNotBeEmpty) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5359,7 +5359,7 @@ func TestSyncedSignaturesMetaDB(t *testing.T) { defer dcm.StopServer() // Trigger SyncOnDemand - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + tag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + tag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5761,7 +5761,7 @@ func TestOnDemandPullsOnce(t *testing.T) { go func(conv C) { defer wg.Done() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) conv.So(err, ShouldBeNil) conv.So(resp.StatusCode(), ShouldEqual, http.StatusOK) }(conv) @@ -5770,7 +5770,7 @@ func TestOnDemandPullsOnce(t *testing.T) { go func(conv C) { defer wg.Done() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) conv.So(err, ShouldBeNil) conv.So(resp.StatusCode(), ShouldEqual, http.StatusOK) }(conv) @@ -5779,7 +5779,7 @@ func TestOnDemandPullsOnce(t *testing.T) { go func(conv C) { defer wg.Done() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) conv.So(err, ShouldBeNil) conv.So(resp.StatusCode(), ShouldEqual, http.StatusOK) }(conv) @@ -5867,7 +5867,7 @@ func TestSignaturesOnDemand(t *testing.T) { defer dcm.StopServer() // sync on demand - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5893,7 +5893,7 @@ func TestSignaturesOnDemand(t *testing.T) { cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig" getCosignManifestURL := srcBaseURL + path.Join(constants.RoutePrefix, repoName, "manifests", cosignEncodedDigest) - mResp, err := resty.R().Get(getCosignManifestURL) + mResp, err := resty.New().R().Get(getCosignManifestURL) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5914,7 +5914,7 @@ func TestSignaturesOnDemand(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -5933,7 +5933,7 @@ func TestSignaturesOnDemand(t *testing.T) { So(err, ShouldBeNil) // sync on demand - resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6011,7 +6011,7 @@ func TestSignaturesOnDemand(t *testing.T) { // trigger getOCIRefs error getReferrersURL := srcBaseURL + path.Join("/v2/", repoName, "referrers", digest.String()) - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.notary.signature"). Get(getReferrersURL) @@ -6030,7 +6030,7 @@ func TestSignaturesOnDemand(t *testing.T) { So(err, ShouldBeNil) } - resp, err = resty.R().Get(destBaseURL + "/v2/" + testSignedImage + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + testSignedImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6108,7 +6108,7 @@ func TestOnlySignaturesOnDemand(t *testing.T) { defer dcm.StopServer() // sync on demand - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6158,7 +6158,7 @@ func TestOnlySignaturesOnDemand(t *testing.T) { artifactURLPath := path.Join("/v2", repoName, "referrers", imageManifestDigest.String()) // based on image manifest digest get referrers - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Type", "application/json"). SetQueryParam("artifactType", "application/vnd.cncf.icecream"). Get(srcBaseURL + artifactURLPath) @@ -6231,7 +6231,7 @@ func TestSyncOnlyDiff(t *testing.T) { defer dcm.StopServer() - resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6326,7 +6326,7 @@ func TestSyncWithDiffDigest(t *testing.T) { blob := make([]byte, size) digest := godigest.FromBytes(blob) - resp, err := resty.R().Get(srcBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(srcBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6337,14 +6337,14 @@ func TestSyncWithDiffDigest(t *testing.T) { err = json.Unmarshal(manifestBlob, &manifest) So(err, ShouldBeNil) - resp, err = resty.R().Post(srcBaseURL + "/v2/" + testImage + "/blobs/uploads/") + resp, err = resty.New().R().Post(srcBaseURL + "/v2/" + testImage + "/blobs/uploads/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := resp.Header().Get("Location") - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", digest.String()). @@ -6369,7 +6369,7 @@ func TestSyncWithDiffDigest(t *testing.T) { modifiedUpstreamManifestDigest := godigest.FromBytes(manifestBody) So(modifiedUpstreamManifestDigest, ShouldNotEqual, originalManifestDigest) - resp, err = resty.R().SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). + resp, err = resty.New().R().SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestBody). Put(srcBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) @@ -6387,7 +6387,7 @@ func TestSyncWithDiffDigest(t *testing.T) { // wait till .sync temp subdir gets removed. waitSync(destDir, testImage) - resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + resp, err = resty.New().R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6591,7 +6591,7 @@ func TestSyncSignaturesDiff(t *testing.T) { cosignManifestTag := strings.Replace(manifestDigest, ":", "-", 1) + ".sig" // get synced cosign manifest from downstream - resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + cosignManifestTag) + resp, err := resty.New().R().Get(destBaseURL + "/v2/" + repoName + "/manifests/" + cosignManifestTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6601,7 +6601,7 @@ func TestSyncSignaturesDiff(t *testing.T) { So(err, ShouldBeNil) // get cosign manifest from upstream - resp, err = resty.R().Get(srcBaseURL + "/v2/" + repoName + "/manifests/" + cosignManifestTag) + resp, err = resty.New().R().Get(srcBaseURL + "/v2/" + repoName + "/manifests/" + cosignManifestTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6812,7 +6812,7 @@ func TestSyncWithDestination(t *testing.T) { generateKeyPairs(tdir) // get manifest digest from source - resp, err := resty.R().Get(srcBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) + resp, err := resty.New().R().Get(srcBaseURL + "/v2/" + repoName + "/manifests/" + testImageTag) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -6983,7 +6983,7 @@ func TestSyncImageIndex(t *testing.T) { err := UploadMultiarchImage(multiarchImage, srcBaseURL, "index", "latest") So(err, ShouldBeNil) - resp, err := resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err := resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(srcBaseURL + "/v2/index/manifests/latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7002,7 +7002,7 @@ func TestSyncImageIndex(t *testing.T) { t.Logf("waitsync(%s, %s)", dctlr.Config.Storage.RootDirectory, "index") waitSync(dctlr.Config.Storage.RootDirectory, "index") - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(destBaseURL + "/v2/index/manifests/latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7029,7 +7029,7 @@ func TestSyncImageIndex(t *testing.T) { dcm.StartAndWait(dctlr.Config.HTTP.Port) defer dcm.StopServer() - resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). + resp, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). Get(destBaseURL + "/v2/index/manifests/latest") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -7131,14 +7131,14 @@ func signImage(tdir, port, repoName string, digest godigest.Digest) { func pushRepo(url, repoName string) godigest.Digest { // create a blob/layer - resp, err := resty.R().Post(url + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) + resp, err := resty.New().R().Post(url + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName)) if err != nil { panic(err) } loc := test.Location(url, resp) - _, err = resty.R().Get(loc) + _, err = resty.New().R().Get(loc) if err != nil { panic(err) } @@ -7146,14 +7146,14 @@ func pushRepo(url, repoName string) godigest.Digest { content := []byte("this is a blob") digest := godigest.FromBytes(content) - _, err = resty.R().SetQueryParam("digest", digest.String()). + _, err = resty.New().R().SetQueryParam("digest", digest.String()). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) if err != nil { panic(err) } // upload scratch image config - resp, err = resty.R(). + resp, err = resty.New().R(). Post(fmt.Sprintf("%s/v2/%s/blobs/uploads/", url, repoName)) if err != nil { panic(err) @@ -7166,7 +7166,7 @@ func pushRepo(url, repoName string) godigest.Digest { loc = test.Location(url, resp) cblob, cdigest := ispec.DescriptorEmptyJSON.Data, ispec.DescriptorEmptyJSON.Digest - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -7182,7 +7182,7 @@ func pushRepo(url, repoName string) godigest.Digest { } // upload image config blob - resp, err = resty.R(). + resp, err = resty.New().R(). Post(fmt.Sprintf("%s/v2/%s/blobs/uploads/", url, repoName)) if err != nil { panic(err) @@ -7195,7 +7195,7 @@ func pushRepo(url, repoName string) godigest.Digest { loc = test.Location(url, resp) cblob, cdigest = GetRandomImageConfig() - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -7239,7 +7239,7 @@ func pushRepo(url, repoName string) godigest.Digest { digest = godigest.FromBytes(content) - _, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). + _, err = resty.New().R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). SetBody(content).Put(url + fmt.Sprintf("/v2/%s/manifests/%s", repoName, testImageTag)) if err != nil { panic(err) @@ -7313,7 +7313,7 @@ func pushRepo(url, repoName string) godigest.Digest { adigest = godigest.FromBytes(content) // put OCI reference image mediaType artifact - _, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + _, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(url + fmt.Sprintf("/v2/%s/manifests/%s", repoName, adigest.String())) if err != nil { panic(err) @@ -7327,7 +7327,7 @@ func pushRepo(url, repoName string) godigest.Digest { adigest = godigest.FromBytes(content) // put OCI reference artifact mediaType artifact - _, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). + _, err = resty.New().R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(url + fmt.Sprintf("/v2/%s/manifests/%s", repoName, adigest.String())) if err != nil { panic(err) @@ -7351,7 +7351,7 @@ func waitSync(rootDir, repoName string) { } func pushBlob(url string, repoName string, buf []byte) godigest.Digest { - resp, err := resty.R(). + resp, err := resty.New().R(). Post(fmt.Sprintf("%s/v2/%s/blobs/uploads/", url, repoName)) if err != nil { panic(err) @@ -7365,7 +7365,7 @@ func pushBlob(url string, repoName string, buf []byte) godigest.Digest { digest := godigest.FromBytes(buf) - resp, err = resty.R(). + resp, err = resty.New().R(). SetContentLength(true). SetHeader("Content-Length", strconv.Itoa(len(buf))). SetHeader("Content-Type", "application/octet-stream"). diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index 2084678ad..b8e9a3e70 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -81,7 +81,7 @@ func TestAuditLogMessages(t *testing.T) { defer auditFile.Close() Convey("Test GET request", func() { - resp, err := resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/") + resp, err := resty.New().R().SetBasicAuth(username, password).Get(baseURL + "/v2/") So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) @@ -93,7 +93,7 @@ func TestAuditLogMessages(t *testing.T) { Convey("Test POST request", func() { repoName := "everyone/isallowed" path := "/v2/" + repoName + "/blobs/uploads/" - resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path) + resp, err := resty.New().R().SetBasicAuth(username, password).Post(baseURL + path) So(err, ShouldBeNil) So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) @@ -127,7 +127,7 @@ func TestAuditLogMessages(t *testing.T) { Convey("Test PUT and DELETE request", func() { // create upload path := "/v2/repo/blobs/uploads/" - resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path) + resp, err := resty.New().R().SetBasicAuth(username, password).Post(baseURL + path) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -165,7 +165,7 @@ func TestAuditLogMessages(t *testing.T) { So(digest, ShouldNotBeNil) // blob upload - resp, err = resty.R().SetQueryParam("digest", digest.String()). + resp, err = resty.New().R().SetQueryParam("digest", digest.String()). SetBasicAuth(username, password). SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc) So(err, ShouldBeNil) @@ -200,7 +200,7 @@ func TestAuditLogMessages(t *testing.T) { So(auditLog.Object, ShouldEqual, putPath) // delete this blob - resp, err = resty.R().SetBasicAuth(username, password).Delete(blobLoc) + resp, err = resty.New().R().SetBasicAuth(username, password).Delete(blobLoc) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) So(resp.Header().Get("Content-Length"), ShouldEqual, "0") @@ -233,7 +233,7 @@ func TestAuditLogMessages(t *testing.T) { Convey("Test PATCH request", func() { path := "/v2/repo/blobs/uploads/" - resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path) + resp, err := resty.New().R().SetBasicAuth(username, password).Post(baseURL + path) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) loc := test.Location(baseURL, resp) @@ -274,7 +274,7 @@ func TestAuditLogMessages(t *testing.T) { // write a chunk contentRange := fmt.Sprintf("%d-%d", 0, len(chunk)-1) - resp, err = resty.R().SetBasicAuth(username, password). + resp, err = resty.New().R().SetBasicAuth(username, password). SetHeader("Content-Type", "application/octet-stream"). SetHeader("Content-Range", contentRange).SetBody(chunk).Patch(loc) diff --git a/pkg/storage/gc/gc_test.go b/pkg/storage/gc/gc_test.go index 25b8c30c0..9831d755c 100644 --- a/pkg/storage/gc/gc_test.go +++ b/pkg/storage/gc/gc_test.go @@ -105,7 +105,7 @@ func TestGarbageCollectAndRetention(t *testing.T) { defer store.Delete(context.Background(), rootDir) //nolint: errcheck // create bucket if it doesn't exists - _, err = resty.R().Put("http://" + os.Getenv("S3MOCK_ENDPOINT") + "/" + bucket) + _, err = resty.New().R().Put("http://" + os.Getenv("S3MOCK_ENDPOINT") + "/" + bucket) if err != nil { panic(err) } diff --git a/pkg/storage/s3/s3_test.go b/pkg/storage/s3/s3_test.go index c928a62e4..543e7c500 100644 --- a/pkg/storage/s3/s3_test.go +++ b/pkg/storage/s3/s3_test.go @@ -115,7 +115,7 @@ func createStoreDriver(rootDir string) driver.StorageDriver { } // create bucket if it doesn't exists - _, err = resty.R().Put("http://" + endpoint + "/" + bucket) + _, err = resty.New().R().Put("http://" + endpoint + "/" + bucket) if err != nil { panic(err) } diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go index fa64bf6cd..96c2e6ed6 100644 --- a/pkg/storage/storage_test.go +++ b/pkg/storage/storage_test.go @@ -88,7 +88,7 @@ func createObjectsStore(rootDir string, cacheDir string) ( } // create bucket if it doesn't exists - _, err = resty.R().Put("http://" + endpoint + "/" + bucket) + _, err = resty.New().R().Put("http://" + endpoint + "/" + bucket) if err != nil { panic(err) } diff --git a/pkg/test/common/utils.go b/pkg/test/common/utils.go index 2234ec100..f97dde69a 100644 --- a/pkg/test/common/utils.go +++ b/pkg/test/common/utils.go @@ -115,7 +115,7 @@ func NewControllerManager(controller Controller) ControllerManager { func WaitTillServerReady(url string) { for { - _, err := resty.R().Get(url) + _, err := resty.New().R().Get(url) if err == nil { break } diff --git a/pkg/test/image-utils/upload.go b/pkg/test/image-utils/upload.go index 63f6c07a5..ea32f716d 100644 --- a/pkg/test/image-utils/upload.go +++ b/pkg/test/image-utils/upload.go @@ -29,7 +29,7 @@ func UploadImage(img Image, baseURL, repo, ref string) error { } for _, blob := range img.Layers { - resp, err := resty.R().Post(baseURL + "/v2/" + repo + "/blobs/uploads/") + resp, err := resty.New().R().Post(baseURL + "/v2/" + repo + "/blobs/uploads/") if err != nil { return err } @@ -42,7 +42,7 @@ func UploadImage(img Image, baseURL, repo, ref string) error { digest := digestAlgorithm.FromBytes(blob).String() - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", digest). @@ -77,7 +77,7 @@ func UploadImage(img Image, baseURL, repo, ref string) error { cdigest = ispec.DescriptorEmptyJSON.Digest } - resp, err := resty.R(). + resp, err := resty.New().R(). Post(baseURL + "/v2/" + repo + "/blobs/uploads/") if err = inject.Error(err); err != nil { return err @@ -90,7 +90,7 @@ func UploadImage(img Image, baseURL, repo, ref string) error { loc := tcommon.Location(baseURL, resp) // uploading blob should get 201 - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). SetQueryParam("digest", cdigest.String()). @@ -114,7 +114,7 @@ func UploadImage(img Image, baseURL, repo, ref string) error { } } - resp, err = resty.R(). + resp, err = resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageManifest). SetBody(manifestBlob). Put(baseURL + "/v2/" + repo + "/manifests/" + ref) @@ -134,7 +134,7 @@ func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password stri } for _, blob := range img.Layers { - resp, err := resty.R(). + resp, err := resty.New().R(). SetBasicAuth(user, password). Post(baseURL + "/v2/" + repo + "/blobs/uploads/") if err != nil { @@ -149,7 +149,7 @@ func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password stri digest := digestAlgorithm.FromBytes(blob).String() - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(user, password). SetHeader("Content-Length", strconv.Itoa(len(blob))). SetHeader("Content-Type", "application/octet-stream"). @@ -177,7 +177,7 @@ func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password stri cdigest = ispec.DescriptorEmptyJSON.Digest } - resp, err := resty.R(). + resp, err := resty.New().R(). SetBasicAuth(user, password). Post(baseURL + "/v2/" + repo + "/blobs/uploads/") if err = inject.Error(err); err != nil { @@ -191,7 +191,7 @@ func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password stri loc := tcommon.Location(baseURL, resp) // uploading blob should get 201 - resp, err = resty.R(). + resp, err = resty.New().R(). SetBasicAuth(user, password). SetHeader("Content-Length", strconv.Itoa(len(cblob))). SetHeader("Content-Type", "application/octet-stream"). @@ -212,7 +212,7 @@ func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password stri return err } - _, err = resty.R(). + _, err = resty.New().R(). SetBasicAuth(user, password). SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). SetBody(manifestBlob). @@ -241,7 +241,7 @@ func UploadMultiarchImage(multiImage MultiarchImage, baseURL string, repo, ref s } } - resp, err := resty.R(). + resp, err := resty.New().R(). SetHeader("Content-type", ispec.MediaTypeImageIndex). SetBody(indexBlob). Put(baseURL + "/v2/" + repo + "/manifests/" + ref) @@ -254,7 +254,7 @@ func UploadMultiarchImage(multiImage MultiarchImage, baseURL string, repo, ref s } func DeleteImage(repo, reference, baseURL string) (int, error) { - resp, err := resty.R().Delete( + resp, err := resty.New().R().Delete( fmt.Sprintf(baseURL+"/v2/%s/manifests/%s", repo, reference), ) if err != nil {