From 73ab1dc86eccd97e35fbbd25baf66273a3907863 Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo Date: Thu, 19 Oct 2023 06:11:11 +0200 Subject: [PATCH] fix tests --- .github/workflows/ci.yml | 4 +- .../test/client/service-account_test.go | 50 +++++++++++++++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 043ed6dd..3a5df972 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,7 @@ jobs: name: Matrix Acceptance Tests needs: build runs-on: ubuntu-latest - if: "!github.event.pull_request.head.repo.fork" +# if: "!github.event.pull_request.head.repo.fork" timeout-minutes: 15 strategy: fail-fast: false @@ -171,7 +171,7 @@ jobs: cleanup: name: Cleanup - if: "!github.event.pull_request.head.repo.fork" +# if: "!github.event.pull_request.head.repo.fork" needs: tests-acceptance runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/twingate/internal/test/client/service-account_test.go b/twingate/internal/test/client/service-account_test.go index 43da930c..e18f9db3 100644 --- a/twingate/internal/test/client/service-account_test.go +++ b/twingate/internal/test/client/service-account_test.go @@ -298,6 +298,16 @@ func TestUpdateServiceAccountEmptyResponse(t *testing.T) { func TestDeleteServiceAccountOk(t *testing.T) { t.Run("Test Twingate Resource : Delete Service Account - Ok", func(t *testing.T) { + readAccountResponse := `{ + "data": { + "serviceAccount": { + "id": "account-id", + "name": "test-account", + "keys": null + } + } + }` + jsonResponse := `{ "data": { "serviceAccountDelete": { @@ -310,7 +320,11 @@ func TestDeleteServiceAccountOk(t *testing.T) { c := newHTTPMockClient() defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", c.GraphqlServerURL, - httpmock.NewStringResponder(http.StatusOK, jsonResponse)) + MultipleResponders( + httpmock.NewStringResponder(http.StatusOK, readAccountResponse), + httpmock.NewStringResponder(http.StatusOK, jsonResponse), + ), + ) err := c.DeleteServiceAccount(context.Background(), "account-id") @@ -324,16 +338,30 @@ func TestDeleteServiceAccountWithEmptyID(t *testing.T) { err := c.DeleteServiceAccount(context.Background(), "") - assert.EqualError(t, err, `failed to delete service account: id is empty`) + assert.EqualError(t, err, `failed to read service account: id is empty`) }) } func TestDeleteServiceAccountRequestError(t *testing.T) { t.Run("Test Twingate Resource : Delete Service Account - Request Error", func(t *testing.T) { + readAccountResponse := `{ + "data": { + "serviceAccount": { + "id": "account-id", + "name": "test-account", + "keys": null + } + } + }` + c := newHTTPMockClient() defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", c.GraphqlServerURL, - httpmock.NewErrorResponder(errBadRequest)) + MultipleResponders( + httpmock.NewStringResponder(http.StatusOK, readAccountResponse), + httpmock.NewErrorResponder(errBadRequest), + ), + ) err := c.DeleteServiceAccount(context.Background(), "account-id") @@ -343,6 +371,16 @@ func TestDeleteServiceAccountRequestError(t *testing.T) { func TestDeleteServiceAccountResponseError(t *testing.T) { t.Run("Test Twingate Resource : Delete Service Account - Response Error", func(t *testing.T) { + readAccountResponse := `{ + "data": { + "serviceAccount": { + "id": "account-id", + "name": "test-account", + "keys": null + } + } + }` + jsonResponse := `{ "data": { "serviceAccountDelete": { @@ -355,7 +393,11 @@ func TestDeleteServiceAccountResponseError(t *testing.T) { c := newHTTPMockClient() defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", c.GraphqlServerURL, - httpmock.NewStringResponder(http.StatusOK, jsonResponse)) + MultipleResponders( + httpmock.NewStringResponder(http.StatusOK, readAccountResponse), + httpmock.NewStringResponder(http.StatusOK, jsonResponse), + ), + ) err := c.DeleteServiceAccount(context.Background(), "account-id")