From c142cd98e18c792aa14479818e80f0abec26cd5a Mon Sep 17 00:00:00 2001 From: Andy Zhao Date: Wed, 29 Jun 2022 12:29:11 -0700 Subject: [PATCH] Add Github Action for integration test (#135) This will replace the old Travis CI presubmits, which appears to have stopped working due to deprecation. Also patching impersonation test. --- .github/workflows/integration-test.yml | 26 +++++++++++++++++++ integration/cli_test.go | 21 +++++---------- integration/golden/fetch-impersonation.golden | 23 +--------------- 3 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/integration-test.yml diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 0000000..8b514bc --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,26 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.13 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./integration/... + diff --git a/integration/cli_test.go b/integration/cli_test.go index 5970689..cc95e03 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -516,21 +516,12 @@ func TestServiceAccountImpersonationFlow(t *testing.T) { } processOutput := func(output string) string { - - method := "\"method\": \"google.iam.credentials.v1.IAMCredentials.GenerateAccessToken\"" - service := "\"service\": \"iamcredentials.googleapis.com\"" - - mPos := strings.Index(output, method) - sPos := strings.Index(output, service) - - // If service appears later than method, revert order to match output - if sPos > mPos { - output = strings.Replace(output, method, "**MARKER-1**", 1) - output = strings.Replace(output, service, method, 1) - output = strings.Replace(output, "**MARKER-1**", service, 1) - } - - return output + //Error details are constantly changing, so we will strip out "error.details" field. + var jsonData map[string]interface{} + json.Unmarshal([]byte(output), &jsonData) // nolint:errcheck + delete(jsonData["error"].(map[string]interface{}), "details") + jsonString, _ := json.Marshal(jsonData) + return string(jsonString) } runTestScenariosWithInputAndProcessedOutput(t, tests, nil, processOutput) diff --git a/integration/golden/fetch-impersonation.golden b/integration/golden/fetch-impersonation.golden index d76c1df..97a6bc0 100644 --- a/integration/golden/fetch-impersonation.golden +++ b/integration/golden/fetch-impersonation.golden @@ -1,22 +1 @@ -{ - "error": { - "code": 401, - "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", - "status": "UNAUTHENTICATED", - "details": [ - { - "@type": "type.googleapis.com/google.rpc.DebugInfo", - "detail": "Authentication error: 16; Error Details: Credential sent is invalid. Unknown token version 0 for token string: ya29.GltDB_y~" - }, - { - "@type": "type.googleapis.com/google.rpc.ErrorInfo", - "reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED", - "metadata": { - "service": "iamcredentials.googleapis.com", - "method": "google.iam.credentials.v1.IAMCredentials.GenerateAccessToken" - } - } - ] - } -} - +{"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}} \ No newline at end of file