diff --git a/cmd/abapLandscapePortalUpdateAddOnProduct.go b/cmd/abapLandscapePortalUpdateAddOnProduct.go index 63a08268cb..73eb671abe 100644 --- a/cmd/abapLandscapePortalUpdateAddOnProduct.go +++ b/cmd/abapLandscapePortalUpdateAddOnProduct.go @@ -101,37 +101,37 @@ func runAbapLandscapePortalUpdateAddOnProduct(config *abapLandscapePortalUpdateA return err } - // update addOn in the system + // update addon in the system updateAddOnErr := updateAddOn(config, client, clientAT, servKey, systemId, &reqId) if updateAddOnErr != nil { - err = fmt.Errorf("Failed to update addOn in the system with systemId %v. Error: %v\n", systemId, updateAddOnErr) + err = fmt.Errorf("Failed to update addon in the system with systemId %v. Error: %v\n", systemId, updateAddOnErr) return err } // query status of request getStatusOfUpdateAddOnErr := getStatusOfUpdateAddOn(config, client, clientAT, servKey, reqId, &reqStatus, &getStatusReq) if getStatusOfUpdateAddOnErr != nil { - err = fmt.Errorf("Failed to get status of addOn update request %v. Error: %v\n", reqId, getStatusOfUpdateAddOnErr) + err = fmt.Errorf("Failed to get status of addon update request %v. Error: %v\n", reqId, getStatusOfUpdateAddOnErr) return err } - // keep pulling status of addOn update request until it reaches a final status (C/E/X) + // keep pulling status of addon update request until it reaches a final status (C/E/X) for reqStatus == StatusInProgress || reqStatus == StatusScheduled { // pull status every 30s time.Sleep(30 * time.Second) pullStatusOfUpdateAddOnErr := pullStatusOfUpdateAddOn(client, &getStatusReq, reqId, &reqStatus) if pullStatusOfUpdateAddOnErr != nil { - err = fmt.Errorf("Error happened when waiting for the addOn update request %v to reach a final status. Error: %v\n", reqId, pullStatusOfUpdateAddOnErr) + err = fmt.Errorf("Error happened when waiting for the addon update request %v to reach a final status. Error: %v\n", reqId, pullStatusOfUpdateAddOnErr) return err } } - // respond to the final status of addOn update + // respond to the final status of addon update respondToUpdateAddOnFinalStatusErr := respondToUpdateAddOnFinalStatus(config, client, clientAT, servKey, reqId, reqStatus) if respondToUpdateAddOnFinalStatusErr != nil { - err = fmt.Errorf("The final status of addon update is %v. Error: %v", reqStatus, respondToUpdateAddOnFinalStatusErr) + err = fmt.Errorf("The final status of addon update is %v. Error: %v\n", reqStatus, respondToUpdateAddOnFinalStatusErr) return err } @@ -272,7 +272,7 @@ func getSystemBySystemNumber(config *abapLandscapePortalUpdateAddOnProductOption return nil } -// this function is used to define and maintain the request body of querying status of addOn update request, and send request to pull the status of request +// this function is used to define and maintain the request body of querying status of addon update request, and send request to pull the status of request func getStatusOfUpdateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, client http.Client, clientAT http.Client, servKey serviceKey, reqId string, status *string, getStatusReq *http.Request) error { // get access token accessToken, getAccessTokenErr := getLPAPIAccessToken(clientAT, servKey) @@ -313,7 +313,7 @@ func getStatusOfUpdateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions return nil } -// this function is used to pull status of addOn update request and maintain the status +// this function is used to pull status of addon update request and maintain the status func pullStatusOfUpdateAddOn(client http.Client, req *http.Request, reqId string, status *string) error { // send request and get response resp, getStatusErr := client.Do(req) @@ -344,7 +344,7 @@ func pullStatusOfUpdateAddOn(client http.Client, req *http.Request, reqId string return nil } -// this function is used to update addOn +// this function is used to update addon func updateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, client http.Client, clientAT http.Client, servKey serviceKey, systemId string, reqId *string) error { // get access token accessToken, getAccessTokenErr := getLPAPIAccessToken(clientAT, servKey) @@ -398,7 +398,7 @@ func updateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, client ht // error case of response status code being non 200 if resp.StatusCode != http.StatusOK { - err := fmt.Errorf("Unexpected response status %v received when updating addOn in system with systemId %v.\n", resp.Status, systemId) + err := fmt.Errorf("Unexpected response status %v received when updating addon in system with systemId %v.\n", resp.Status, systemId) return err } @@ -411,11 +411,11 @@ func updateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, client ht *reqId = respBody.RequestId - fmt.Printf("Successfully triggered addOn update in system with systemId %v, the returned request id is %v.\n", systemId, respBody.RequestId) + fmt.Printf("Successfully triggered addon update in system with systemId %v, the returned request id is %v.\n", systemId, respBody.RequestId) return nil } -// this function is used to cancel addOn update +// this function is used to cancel addon update func cancelUpdateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, client http.Client, clientAT http.Client, servKey serviceKey, reqId string) error { // get access token accessToken, getAccessTokenErr := getLPAPIAccessToken(clientAT, servKey) @@ -454,34 +454,34 @@ func cancelUpdateAddOn(config *abapLandscapePortalUpdateAddOnProductOptions, cli // error case of response status code being non 204 if resp.StatusCode != http.StatusNoContent { - err := fmt.Errorf("Unexpected response status %v received when canceling addOn update request %v.\n", resp.Status, reqId) + err := fmt.Errorf("Unexpected response status %v received when canceling addon update request %v.\n", resp.Status, reqId) return err } - fmt.Printf("Successfully canceled addOn update request %v.\n", reqId) + fmt.Printf("Successfully canceled addon update request %v.\n", reqId) return nil } -// this function is used to respond to a final status of addOn update +// this function is used to respond to a final status of addon update func respondToUpdateAddOnFinalStatus(config *abapLandscapePortalUpdateAddOnProductOptions, client http.Client, clientAT http.Client, servKey serviceKey, reqId string, status string) error { switch status { case StatusComplete: - fmt.Printf("AddOn update request %v succeeded.\n", reqId) + fmt.Println("Addon update succeeded.") case StatusError: - fmt.Printf("AddOn update failed and request %v will be canceled.\n", reqId) + fmt.Println("Addon update failed and will be canceled.") cancelUpdateAddOnErr := cancelUpdateAddOn(config, client, clientAT, servKey, reqId) if cancelUpdateAddOnErr != nil { - err := fmt.Errorf("Failed to cancel addOn update request %v. Error: %v\n", reqId, cancelUpdateAddOnErr) + err := fmt.Errorf("Failed to cancel addon update. Error: %v\n", cancelUpdateAddOnErr) return err } - err := fmt.Errorf("AddOn update failed.") + err := fmt.Errorf("Addon update failed.\n") return err case StatusAborted: - fmt.Println("AddOn update is aborted.") - err := fmt.Errorf("AddOn update is aborted.") + fmt.Println("Addon update is aborted.") + err := fmt.Errorf("Addon update is aborted.\n") return err } diff --git a/cmd/abapLandscapePortalUpdateAddOnProduct_test.go b/cmd/abapLandscapePortalUpdateAddOnProduct_test.go index db8c18dab2..9816bb0608 100644 --- a/cmd/abapLandscapePortalUpdateAddOnProduct_test.go +++ b/cmd/abapLandscapePortalUpdateAddOnProduct_test.go @@ -161,11 +161,11 @@ func convertMockedReqToHttpReq(mockedReq mockedClientReq) http.Request { return httpReq } -// this function is used to mock the last part of runAbapLandcapePortalUpdateAddOnProduct "keep pulling status of update AddOn request until it reaches a final status (C/E/X)" +// this function is used to mock the last part of runAbapLandcapePortalUpdateAddOnProduct "keep pulling status of update addon request until it reaches a final status (C/E/X)" func keepPullingUntilFinalStatusReached(fromStatus *string, toStatus string, mockedServer *httptest.Server, req mockedClientReq) error { httpReq := convertMockedReqToHttpReq(req) - // mock the process of pulling status of update AddOn request + // mock the process of pulling status of update addon request for i := 0; i < 3; i++ { time.Sleep(1 * time.Second) err := pullStatusOfUpdateAddOn(httpClient, &httpReq, "some-request-guid", fromStatus) @@ -175,7 +175,7 @@ func keepPullingUntilFinalStatusReached(fromStatus *string, toStatus string, moc } } - // mock the server which returns the update AddOn request with a final status, and update the url of http request + // mock the server which returns the update addon request with a final status, and update the url of http request wantedRequest := reqEntity{ RequestId: "some-req-id", ZoneId: "some-zone-id", @@ -184,10 +184,10 @@ func keepPullingUntilFinalStatusReached(fromStatus *string, toStatus string, moc } mockedServer = mockServer(&req, resp_200, wantedRequest) - req.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/some-req-id") + req.url = parseRawURL(mockedServer.URL + "/api/requests/some-req-id") httpReq = convertMockedReqToHttpReq(req) - // pull the status of update AddOn request from the newly modified server + // pull the status of update addon request from the newly modified server err := pullStatusOfUpdateAddOn(httpClient, &httpReq, "some-req-id", fromStatus) if err != nil { @@ -262,7 +262,7 @@ func TestGetLPAPIAccessToken(t *testing.T) { accessToken, err := getLPAPIAccessToken(httpClientAT, servKey_temp) - expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when getting access token of LP API.") + expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when getting access token of LP API.\n") accessToken, err = getLPAPIAccessToken(httpClientAT, servKey_temp) assert.Equal(t, "", accessToken) @@ -282,13 +282,13 @@ func TestGetLPAPIAccessToken(t *testing.T) { func TestGetSystemBySystemNumber(t *testing.T) { json.Unmarshal([]byte(lPAPIServiceKey), &servKey) accessToken, servKey_temp := mockGetLPAPIAccessToken(httpClientAT, servKey) - rawURL := servKey.Url + "/api/v1.0/systems/" + updateAddOnConfig.AbapSystemNumber + rawURL := servKey.Url + "/api/systems/" + updateAddOnConfig.AbapSystemNumber req := mockedClientReq{ url: parseRawURL(rawURL), method: http.MethodGet, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -323,7 +323,7 @@ func TestGetSystemBySystemNumber(t *testing.T) { err := getSystemBySystemNumber(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, &systemId) - expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when getting system with systemNumber %v.", updateAddOnConfig.AbapSystemNumber) + expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when getting system with systemNumber %v.\n", updateAddOnConfig.AbapSystemNumber) assert.Equal(t, "", systemId) assert.Equal(t, expectedErr, err) @@ -343,13 +343,13 @@ func TestGetStatusOfUpdateAddOn(t *testing.T) { json.Unmarshal([]byte(lPAPIServiceKey), &servKey) reqId := "some-req-id" accessToken, servKey_temp := mockGetLPAPIAccessToken(httpClientAT, servKey) - rawURL := servKey.Url + "/api/v1.0/requests/" + reqId + rawURL := servKey.Url + "/api/requests/" + reqId req := mockedClientReq{ url: parseRawURL(rawURL), method: http.MethodGet, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -375,7 +375,7 @@ func TestGetStatusOfUpdateAddOn(t *testing.T) { assert.Equal(t, wantedRequest.Status, status) assert.Equal(t, nil, err) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, req.method, getStatusReq.Method) assert.Equal(t, req.header, getStatusReq.Header) }) @@ -388,13 +388,13 @@ func TestGetStatusOfUpdateAddOn(t *testing.T) { servKey_temp.Url = mockedServer.URL - expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when getting status of request with id %v.", reqId) + expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when pulling status of request %v.\n", reqId) err := getStatusOfUpdateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, &status, &getStatusReq) assert.Equal(t, "", status) assert.Equal(t, expectedErr, err) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, req.method, getStatusReq.Method) assert.Equal(t, req.header, getStatusReq.Header) }) @@ -415,7 +415,7 @@ func TestUpdateAddOn(t *testing.T) { json.Unmarshal([]byte(lPAPIServiceKey), &servKey) systemId := "some-system-id" accessToken, servKey_temp := mockGetLPAPIAccessToken(httpClientAT, servKey) - rawURL := servKey.Url + "/api/v1.0/systems/" + systemId + "/deployProduct" + rawURL := servKey.Url + "/api/systems/" + systemId + "/deployProduct" updateAddOnReqBody := updateAddOnReq{ ProductName: "some-product-name", ProductVersion: "some-product-version", @@ -426,7 +426,7 @@ func TestUpdateAddOn(t *testing.T) { url: parseRawURL(rawURL), method: http.MethodPost, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -441,7 +441,7 @@ func TestUpdateAddOn(t *testing.T) { } t.Parallel() - t.Run("Successfully update AddOn in the system", func(t *testing.T) { + t.Run("Successfully update addon in the system", func(t *testing.T) { var reqId string mockedServer := mockServer(&req, resp_200, wantedRequest) @@ -454,21 +454,21 @@ func TestUpdateAddOn(t *testing.T) { assert.Equal(t, nil, err) }) - t.Run("Non-200 status code returned when updating AddOn in a system", func(t *testing.T) { + t.Run("Non-200 status code returned when updating addon in a system", func(t *testing.T) { var reqId string mockedServer := mockServer(&req, resp_400, nil) servKey_temp.Url = mockedServer.URL - expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when updating AddOn in system with systemId %v.", systemId) + expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when updating addon in system with systemId %v.\n", systemId) err := updateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, systemId, &reqId) assert.Equal(t, "", reqId) assert.Equal(t, expectedErr, err) }) - t.Run("Error returned when returned when updating AddOn in a system", func(t *testing.T) { + t.Run("Error returned when returned when updating addon in a system", func(t *testing.T) { var reqId string err := updateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey, systemId, &reqId) @@ -482,20 +482,20 @@ func TestCancelUpdateAddOn(t *testing.T) { json.Unmarshal([]byte(lPAPIServiceKey), &servKey) reqId := "some-req-id" accessToken, servKey_temp := mockGetLPAPIAccessToken(httpClientAT, servKey) - rawURL := servKey.Url + "/api/v1.0/requests/" + reqId + rawURL := servKey.Url + "/api/requests/" + reqId req := mockedClientReq{ url: parseRawURL(rawURL), method: http.MethodPost, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, } t.Parallel() - t.Run("Successfully cancel update AddOn request", func(t *testing.T) { + t.Run("Successfully cancel update addon request", func(t *testing.T) { mockedServer := mockServer(&req, resp_204, nil) servKey_temp.Url = mockedServer.URL @@ -505,18 +505,18 @@ func TestCancelUpdateAddOn(t *testing.T) { assert.Equal(t, nil, err) }) - t.Run("Non-204 status code returned when canceling update AddOn request", func(t *testing.T) { + t.Run("Non-204 status code returned when canceling update addon request", func(t *testing.T) { mockedServer := mockServer(&req, resp_400, nil) servKey_temp.Url = mockedServer.URL - expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when canceling addon update request with id %v.", reqId) + expectedErr := fmt.Errorf("Unexpected response status 400 Bad Request received when canceling addon update request %v.\n", reqId) err := cancelUpdateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId) assert.Equal(t, expectedErr, err) }) - t.Run("Error returned when returned when canceling update AddOn request", func(t *testing.T) { + t.Run("Error returned when returned when canceling update addon request", func(t *testing.T) { err := cancelUpdateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey, reqId) assert.ErrorContains(t, err, "no such host") @@ -524,18 +524,18 @@ func TestCancelUpdateAddOn(t *testing.T) { } func TestRespondToUpdateAddOnFinalStatus(t *testing.T) { - t.Run("Cancel update AddOn request if it failed", func(t *testing.T) { + t.Run("Cancel update addon request if it failed", func(t *testing.T) { json.Unmarshal([]byte(lPAPIServiceKey), &servKey) reqId := "some-req-id" accessToken, servKey_temp := mockGetLPAPIAccessToken(httpClientAT, servKey) - rawURL := servKey.Url + "/api/v1.0/requests/" + reqId + rawURL := servKey.Url + "/api/requests/" + reqId status := "E" req := mockedClientReq{ url: parseRawURL(rawURL), method: http.MethodPost, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -545,7 +545,7 @@ func TestRespondToUpdateAddOnFinalStatus(t *testing.T) { servKey_temp.Url = mockedServer.URL - expectedErr := fmt.Errorf("AddOn update failed.") + expectedErr := fmt.Errorf("Addon update failed.\n") err := respondToUpdateAddOnFinalStatus(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, status) assert.Equal(t, expectedErr, err) @@ -556,6 +556,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { // declare variables var systemId, reqId, reqStatus string var getStatusReq http.Request + // var err error // mock server for getLPAPIAccessToken to get LP API access token json.Unmarshal([]byte(lPAPIServiceKey), &servKey) @@ -576,10 +577,10 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { } req2 := mockedClientReq{ - url: parseRawURL(servKey.Url + "/api/v1.0/systems/" + updateAddOnConfig.AbapSystemNumber), + url: parseRawURL(servKey.Url + "/api/systems/" + updateAddOnConfig.AbapSystemNumber), method: http.MethodGet, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -596,13 +597,13 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { ProductName: "some-product-name", ProductVersion: "some-product-version", } - httpReq := encodeReqBody[updateAddOnReq](updateAddOnReqBody, servKey.Url+"/api/v1.0/systems/"+systemId+"/deployProduct") + httpReq := encodeReqBody[updateAddOnReq](updateAddOnReqBody, servKey.Url+"/api/systems/"+systemId+"/deployProduct") req3 := mockedClientReq{ - url: parseRawURL(servKey.Url + "/api/v1.0/systems/" + systemId + "/deployProduct"), + url: parseRawURL(servKey.Url + "/api/systems/" + systemId + "/deployProduct"), method: http.MethodPost, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -624,10 +625,10 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { // mock server for getStatusOfUpdateAddOn and execute it req4 := mockedClientReq{ - url: parseRawURL(servKey.Url + "/api/v1.0/requests/" + reqId), + url: parseRawURL(servKey.Url + "/api/requests/" + reqId), method: http.MethodGet, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -647,15 +648,15 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { err4 := getStatusOfUpdateAddOn(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, &reqStatus, &getStatusReq) t.Parallel() - t.Run("Successfully update AddOn", func(t *testing.T) { + t.Run("Successfully update addon ", func(t *testing.T) { finalStatus := "C" - // mock pulling status of update AddOn request until final status reaches + // mock pulling status of update addon request until final status reaches mockedClientReq_temp := req4 - mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/" + reqId) + mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/requests/" + reqId) err5 := keepPullingUntilFinalStatusReached(&reqStatus, finalStatus, mockedServer, mockedClientReq_temp) - // mock respond to completed update AddOn + // mock respond to completed update addon err6 := respondToUpdateAddOnFinalStatus(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, reqStatus) // assertions @@ -664,7 +665,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, "some-req-id", reqId) assert.Equal(t, finalStatus, reqStatus) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, nil, err1) assert.Equal(t, nil, err2) @@ -672,18 +673,19 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, nil, err4) assert.Equal(t, nil, err5) assert.Equal(t, nil, err6) + // assert.Equal(t, nil, err) }) - t.Run("Update AddOn request is aborted", func(t *testing.T) { + t.Run("Update addon request is aborted", func(t *testing.T) { finalStatus := "X" - // mock pulling status of update AddOn request until final status reaches + // mock pulling status of update addon request until final status reaches mockedClientReq_temp := req4 - mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/" + reqId) + mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/requests/" + reqId) err5 := keepPullingUntilFinalStatusReached(&reqStatus, finalStatus, mockedServer, mockedClientReq_temp) - // mock respond to abort update AddOn - expectedErr6 := fmt.Errorf("AddOn update is aborted.") + // mock respond to abort update addon + expectedErr6 := fmt.Errorf("Addon update is aborted.\n") err6 := respondToUpdateAddOnFinalStatus(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, reqStatus) // assertions @@ -692,7 +694,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, "some-req-id", reqId) assert.Equal(t, finalStatus, reqStatus) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, nil, err1) assert.Equal(t, nil, err2) @@ -702,20 +704,20 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, expectedErr6, err6) }) - t.Run("Failed to update AddOn", func(t *testing.T) { + t.Run("Failed to update addon ", func(t *testing.T) { finalStatus := "E" - // mock pulling status of update AddOn request until final status reaches + // mock pulling status of update addon request until final status reaches mockedClientReq_temp := req4 - mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/" + reqId) + mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/requests/" + reqId) err5 := keepPullingUntilFinalStatusReached(&reqStatus, finalStatus, mockedServer, mockedClientReq_temp) - // mock respond to cancel update AddOn + // mock respond to cancel update addon req5 := mockedClientReq{ - url: parseRawURL(servKey.Url + "/api/v1.0/requests/" + reqId), + url: parseRawURL(servKey.Url + "/api/requests/" + reqId), method: http.MethodDelete, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -725,7 +727,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { servKey_temp.Url = mockedServer_cancelUpdateAddOn.URL - expectedErr6 := fmt.Errorf("AddOn update failed.") + expectedErr6 := fmt.Errorf("Addon update failed.\n") err6 := respondToUpdateAddOnFinalStatus(&updateAddOnConfig, httpClient, httpClientAT, servKey_temp, reqId, reqStatus) // assertions @@ -734,7 +736,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, "some-req-id", reqId) assert.Equal(t, finalStatus, reqStatus) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, nil, err1) assert.Equal(t, nil, err2) @@ -747,17 +749,17 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { t.Run("Non-200 status code was returned", func(t *testing.T) { finalStatus := "E" - // mock pulling status of update AddOn request until final status reaches + // mock pulling status of update addon request until final status reaches mockedClientReq_temp := req4 - mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/" + reqId) + mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/requests/" + reqId) err5 := keepPullingUntilFinalStatusReached(&reqStatus, finalStatus, mockedServer, mockedClientReq_temp) - // mock respond to cancel update AddOn + // mock respond to cancel update addon req5 := mockedClientReq{ - url: parseRawURL(servKey.Url + "/api/v1.0/requests/" + reqId), + url: parseRawURL(servKey.Url + "/api/requests/" + reqId), method: http.MethodDelete, header: map[string][]string{ - "Authorization": {"Bearer" + accessToken}, + "Authorization": {"Bearer " + accessToken}, "Content-Type": {"application/json"}, "Accept": {"application/json"}, }, @@ -775,22 +777,22 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, "some-req-id", reqId) assert.Equal(t, finalStatus, reqStatus) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, nil, err1) assert.Equal(t, nil, err2) assert.Equal(t, nil, err3) assert.Equal(t, nil, err4) assert.Equal(t, nil, err5) - assert.Equal(t, err6.Error(), "Failed to cancel addon update. Error: Unexpected response status 400 Bad Request received when canceling addon update request with id some-req-id.") + assert.Equal(t, err6.Error(), "Failed to cancel addon update. Error: Unexpected response status 400 Bad Request received when canceling addon update request some-req-id.\n\n") }) t.Run("Other error returned", func(t *testing.T) { finalStatus := "E" - // mock pulling status of update AddOn request until final status reaches + // mock pulling status of update addon request until final status reaches mockedClientReq_temp := req4 - mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/v1.0/requests/" + reqId) + mockedClientReq_temp.url = parseRawURL(mockedServer.URL + "/api/requests/" + reqId) err5 := keepPullingUntilFinalStatusReached(&reqStatus, finalStatus, mockedServer, mockedClientReq_temp) err6 := respondToUpdateAddOnFinalStatus(&updateAddOnConfig, httpClient, httpClientAT, servKey, reqId, reqStatus) @@ -800,7 +802,7 @@ func TestRunAbapLandcapePortalUpdateAddOnProduct(t *testing.T) { assert.Equal(t, "some-req-id", reqId) assert.Equal(t, finalStatus, reqStatus) assert.Contains(t, mockedServer.URL, getStatusReq.URL.Host) - assert.Equal(t, "/api/v1.0/requests/some-req-id", getStatusReq.URL.Path) + assert.Equal(t, "/api/requests/some-req-id", getStatusReq.URL.Path) assert.Equal(t, nil, err1) assert.Equal(t, nil, err2)