From b1b4fe17f11bb94d0120bcc262509cbdf1d24ff3 Mon Sep 17 00:00:00 2001 From: Mani Bindra Date: Thu, 21 Mar 2024 15:45:21 +0530 Subject: [PATCH] publish end to end test summary reports for arm, bicep and terraform (#37) publish end to end test summary reports for arm, bicep and terraform --- .github/workflows/az-mpf-e2e-arm-bicep.yaml | 16 ++++----- .github/workflows/az-mpf-e2e-terraform.yaml | 36 +++++++++++-------- e2eTests/e2eTerraform_test.go | 4 +++ pkg/domain/authorizationErrorParser_test.go | 2 +- .../terraformAuthorizationChecker.go | 4 +++ 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/.github/workflows/az-mpf-e2e-arm-bicep.yaml b/.github/workflows/az-mpf-e2e-arm-bicep.yaml index a9a4100..dfca9b9 100644 --- a/.github/workflows/az-mpf-e2e-arm-bicep.yaml +++ b/.github/workflows/az-mpf-e2e-arm-bicep.yaml @@ -53,17 +53,17 @@ jobs: export MPF_BICEPEXECPATH=/usr/local/bin/bicep go install github.com/jstemmer/go-junit-report@latest go test ./e2eTests -v -run TestARM TestBicep | tee TestResults-${{ matrix.go-version }}.txt - # | go-junit-report -set-exit-code > TestResults-${{ matrix.go-version }}.xml + cat TestResults-${{ matrix.go-version }}.txt | go-junit-report -set-exit-code > TestResults-${{ matrix.go-version }}.xml - name: Upload Go test results uses: actions/upload-artifact@v4 with: name: Go-results-${{ matrix.go-version }} - path: TestResults-${{ matrix.go-version }}.txt + path: TestResults-${{ matrix.go-version }}.xml - # - name: Test Summary - # uses: test-summary/action@v1 - # with: - # paths: | - # TestResults-${{ matrix.go-version }}.xml - # if: always() + - name: Test Summary + uses: test-summary/action@v1 + with: + paths: | + TestResults-${{ matrix.go-version }}.xml + if: always() diff --git a/.github/workflows/az-mpf-e2e-terraform.yaml b/.github/workflows/az-mpf-e2e-terraform.yaml index 33c1957..4044cc7 100644 --- a/.github/workflows/az-mpf-e2e-terraform.yaml +++ b/.github/workflows/az-mpf-e2e-terraform.yaml @@ -27,10 +27,18 @@ jobs: with: go-version: ${{ matrix.go-version }} - - name: Setup Terraform - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: 1.5.7 + # - name: Setup Terraform + # uses: hashicorp/setup-terraform@v3 + # with: + # terraform_version: 1.5.7 + - name: Install Terraform + run: | + curl -Lo terraform.zip https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip + unzip terraform.zip + # move to working directory + sudo mv terraform /usr/local/bin/terraform + + terraform --version - name: Install dependencies run: go get ./... @@ -47,22 +55,22 @@ jobs: - name: Test with Go run: | - # cd e2eTests which terraform - export MPF_TFPATH=$(which terraform) + export MPF_TFPATH="/usr/local/bin/terraform" + $MPF_TFPATH --version go install github.com/jstemmer/go-junit-report@latest go test ./e2eTests -v -timeout 20m -run TestTerraform | tee TestResults-${{ matrix.go-version }}.txt - # | go-junit-report -set-exit-code > TestResults-${{ matrix.go-version }}.xml + cat TestResults-${{ matrix.go-version }}.txt | go-junit-report -set-exit-code > TestResults-${{ matrix.go-version }}.xml - name: Upload Go test results uses: actions/upload-artifact@v4 with: name: Go-results-${{ matrix.go-version }} - path: TestResults-${{ matrix.go-version }}.txt + path: TestResults-${{ matrix.go-version }}.xml - # - name: Test Summary - # uses: test-summary/action@v1 - # with: - # paths: | - # TestResults-${{ matrix.go-version }}.xml - # if: always() + - name: Test Summary + uses: test-summary/action@v1 + with: + paths: | + TestResults-${{ matrix.go-version }}.xml + if: always() diff --git a/e2eTests/e2eTerraform_test.go b/e2eTests/e2eTerraform_test.go index 5539490..93ba2f9 100644 --- a/e2eTests/e2eTerraform_test.go +++ b/e2eTests/e2eTerraform_test.go @@ -11,6 +11,7 @@ import ( resourceGroupManager "github.com/manisbindra/az-mpf/pkg/infrastructure/resourceGroupManager" sproleassignmentmanager "github.com/manisbindra/az-mpf/pkg/infrastructure/spRoleAssignmentManager" "github.com/manisbindra/az-mpf/pkg/usecase" + log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -30,8 +31,11 @@ func TestTerraformACI(t *testing.T) { _, filename, _, _ := runtime.Caller(0) curDir := path.Dir(filename) + log.Infof("curDir: %s", curDir) wrkDir := path.Join(curDir, "../samples/terraform/aci") + log.Infof("wrkDir: %s", wrkDir) varsFile := path.Join(curDir, "../samples/terraform/aci/dev.vars.tfvars") + log.Infof("varsFile: %s", varsFile) ctx := context.Background() diff --git a/pkg/domain/authorizationErrorParser_test.go b/pkg/domain/authorizationErrorParser_test.go index 9290e13..74a9ac1 100644 --- a/pkg/domain/authorizationErrorParser_test.go +++ b/pkg/domain/authorizationErrorParser_test.go @@ -48,7 +48,7 @@ func TestSingleAuthorizationSpaceFailedError(t *testing.T) { } func TestSingleLinkedAuthorizationFailedError(t *testing.T) { - singleLinkedAuthorizationFailedError := "error: LinkedAuthorizationFailed: The client '***REMOVED***' with object id '***REMOVED***' has permission to perform action 'Microsoft.ContainerService/managedClusters/write' on scope '/subscriptions/SSSSSSSS-SSSS-SSSS-SSSS-SSSSSSSSSSSS/resourceGroups/az-mpf-tf-test-rg/providers/Microsoft.ContainerService/managedClusters/aks-32a70ccbb3247e2b'; however, it does not have permission to perform action(s) 'Microsoft.Network/virtualNetworks/subnets/join/action' on the linked scope(s) '/subscriptions/SSSSSSSS-SSSS-SSSS-SSSS-SSSSSSSSSSSS/resourceGroups/az-mpf-tf-test-rg/providers/Microsoft.Network/virtualNetworks/vnet-32a70ccbb3247e2b/subnets/subnet-32a70ccbb3247e2b' (respectively) or the linked scope(s) are invalid." + singleLinkedAuthorizationFailedError := "error: LinkedAuthorizationFailed: The client 'a31fc7f1-1349-4b3c-af16-60422be430cc' with object id 'a31fc7f1-1349-4b3c-af16-60422be430cc' has permission to perform action 'Microsoft.ContainerService/managedClusters/write' on scope '/subscriptions/SSSSSSSS-SSSS-SSSS-SSSS-SSSSSSSSSSSS/resourceGroups/az-mpf-tf-test-rg/providers/Microsoft.ContainerService/managedClusters/aks-32a70ccbb3247e2b'; however, it does not have permission to perform action(s) 'Microsoft.Network/virtualNetworks/subnets/join/action' on the linked scope(s) '/subscriptions/SSSSSSSS-SSSS-SSSS-SSSS-SSSSSSSSSSSS/resourceGroups/az-mpf-tf-test-rg/providers/Microsoft.Network/virtualNetworks/vnet-32a70ccbb3247e2b/subnets/subnet-32a70ccbb3247e2b' (respectively) or the linked scope(s) are invalid." spm, err := GetScopePermissionsFromAuthError(singleLinkedAuthorizationFailedError) l := len(spm) assert.Nil(t, err) diff --git a/pkg/infrastructure/authorizationCheckers/terraform/terraformAuthorizationChecker.go b/pkg/infrastructure/authorizationCheckers/terraform/terraformAuthorizationChecker.go index a343b22..3d16644 100644 --- a/pkg/infrastructure/authorizationCheckers/terraform/terraformAuthorizationChecker.go +++ b/pkg/infrastructure/authorizationCheckers/terraform/terraformAuthorizationChecker.go @@ -50,6 +50,10 @@ func (a *terraformDeploymentConfig) CleanDeployment(mpfConfig domain.MPFConfig) func (a *terraformDeploymentConfig) deployTerraform(mpfConfig domain.MPFConfig) (string, error) { + log.Infof("workingDir: %s", a.workingDir) + log.Infof("varfilePath: %s", a.varFilePath) + log.Infof("execPath: %s", a.execPath) + tf, err := tfexec.NewTerraform(a.workingDir, a.execPath) if err != nil { log.Fatalf("error running NewTerraform: %s", err)