Skip to content

Commit

Permalink
refactor the function name
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveromahony committed Dec 13, 2024
1 parent 49a7a4a commit a071c7d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions test/integration/grpc_management_plane_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ type (
}
)

func setupClient() *resty.Client {
client := resty.New()
client.SetRetryCount(retryCount)
client.SetRetryWaitTime(retryWaitTime)
client.SetRetryMaxWaitTime(retryMaxWaitTime)
client.SetRetryAfter(retryAfter)

return client
}

func retryAfter(_ *resty.Client, _ *resty.Response) (time.Duration, error) {
nBig, err := rand.Int(rand.Reader, big.NewInt(100))
if err != nil {
Expand Down Expand Up @@ -231,7 +241,7 @@ func TestGrpc_ConfigUpload(t *testing.T) {
}`, nginxInstanceID)

url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().SetBody(request).Post(url)
resp, err := setupClient().R().EnableTrace().SetBody(request).Post(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand All @@ -244,16 +254,6 @@ func TestGrpc_ConfigUpload(t *testing.T) {
assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
}

func Client() *resty.Client {
client := resty.New()
client.SetRetryCount(retryCount)
client.SetRetryWaitTime(retryWaitTime)
client.SetRetryMaxWaitTime(retryMaxWaitTime)
client.SetRetryAfter(retryAfter)

return client
}

func TestGrpc_ConfigApply(t *testing.T) {
ctx := context.Background()
teardownTest := setupConnectionTest(t, false, false)
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestGrpc_DataplaneHealthRequest(t *testing.T) {
}`

url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().SetBody(request).Post(url)
resp, err := setupClient().R().EnableTrace().SetBody(request).Post(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand All @@ -426,7 +426,7 @@ func performConfigApply(t *testing.T, nginxInstanceID string) {
t.Helper()

url := fmt.Sprintf("http://%s/api/v1/instance/%s/config/apply", mockManagementPlaneAPIAddress, nginxInstanceID)
resp, err := Client().R().EnableTrace().Post(url)
resp, err := setupClient().R().EnableTrace().Post(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand Down Expand Up @@ -471,15 +471,15 @@ func performInvalidConfigApply(t *testing.T, nginxInstanceID string) {
}
}`, nginxInstanceID)
url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().SetBody(body).Post(url)
resp, err := setupClient().R().EnableTrace().SetBody(body).Post(url)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
}

func getManagementPlaneResponses(t *testing.T, numberOfExpectedResponses int) []*mpi.DataPlaneResponse {
t.Helper()

client := Client()
client := setupClient()
client.AddRetryCondition(
func(r *resty.Response, err error) bool {
responseData := r.Body()
Expand Down Expand Up @@ -521,7 +521,7 @@ func clearManagementPlaneResponses(t *testing.T) {
t.Helper()

url := fmt.Sprintf("http://%s/api/v1/responses", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().Delete(url)
resp, err := setupClient().R().EnableTrace().Delete(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand All @@ -531,7 +531,7 @@ func verifyConnection(t *testing.T, instancesLength int) string {
t.Helper()

url := fmt.Sprintf("http://%s/api/v1/connection", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().Get(url)
resp, err := setupClient().R().EnableTrace().Get(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand Down Expand Up @@ -602,7 +602,7 @@ func verifyConnection(t *testing.T, instancesLength int) string {
func verifyUpdateDataPlaneHealth(t *testing.T) {
t.Helper()

client := Client()
client := setupClient()
client.AddRetryCondition(
func(r *resty.Response, err error) bool {
return r.StatusCode() == http.StatusNotFound
Expand Down Expand Up @@ -646,7 +646,7 @@ func verifyUpdateDataPlaneStatus(t *testing.T) {
t.Helper()

url := fmt.Sprintf("http://%s/api/v1/status", mockManagementPlaneAPIAddress)
resp, err := Client().R().EnableTrace().Get(url)
resp, err := setupClient().R().EnableTrace().Get(url)

require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
Expand Down

0 comments on commit a071c7d

Please sign in to comment.