Skip to content

Commit

Permalink
test: Update unit test target for local development (#490)
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
  • Loading branch information
helayoty authored Mar 22, 2023
1 parent cabfe7e commit 604b142
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ env:

jobs:
export-registry:
if: contains(github.event.pull_request.title, 'helm')
runs-on: ubuntu-20.04
outputs:
registry: ${{ steps.export.outputs.registry }}
Expand Down
32 changes: 4 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: azure-aci-test
name: unit-tests

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
pull_request_target:
pull_request:
branches:
- master
- release-**
Expand All @@ -19,18 +19,8 @@ env:
GO_VERSION: '1.19'

jobs:
tests:
unit-tests:
runs-on: ubuntu-20.04
env:
ACTIVEDIRECTORYENDPOINTURL: "https://login.microsoftonline.com"
RESOURCEMANAGERENDPOINTURL: "https://management.azure.com/"
ACTIVEDIRECTORYGRAPHRESOURCEID: "https://login.microsoftonline.com"
SQLMANAGEMENTENDPOINTURL: "https://management.core.windows.net:8443/"
GALLERYENDPOINTURL: "https://gallery.azure.com/"
MANAGEMENTENDPOINTURL: "https://manage.windowsazure.com/"
CLIENTSECRET: ${{ secrets.CLIENT_SECRET }}
WORKSPACEKEY: ${{ secrets.OMS_WORKSPACE_KEY }}

environment: test
steps:
- name: Set up Go ${{ env.GO_VERSION }}
Expand All @@ -46,22 +36,8 @@ jobs:

- name: Run unit tests & Generate coverage
env:
clientId: ${{ secrets.CLIENTID }}
subscriptionId: ${{ secrets.SUBSCRIPTIONID }}
tenantId: ${{ secrets.TENANT_ID }}
activeDirectoryEndpointUrl: ${{ env.ACTIVEDIRECTORYENDPOINTURL }}
resourceManagerEndpointUrl: ${{ env.RESOURCEMANAGERENDPOINTURL }}
activeDirectoryGraphResourceId: ${{ env.ACTIVEDIRECTORYGRAPHRESOURCEID }}
sqlManagementEndpointUrl: ${{ env.SQLMANAGEMENTENDPOINTURL }}
galleryEndpointUrl: ${{ env.GALLERYENDPOINTURL }}
managementEndpointUrl: ${{ env.MANAGEMENTENDPOINTURL }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
omsworkspaceID: ${{ secrets.OMSWORKSPACEID }}
omsworkspaceKey: ${{ secrets.OMS_WORKSPACE_KEY }}
E2E_REGION: ${{ secrets.E2E_REGION}}
run: |
make testauth test
make unit-tests
- name: Upload Codecov report
uses: codecov/codecov-action@v3
Expand Down
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ GO111MODULE := on
export GO111MODULE

TEST_CREDENTIALS_DIR ?= $(abspath .azure)
TEST_AKS_CREDENTIALS_JSON ?= $(TEST_CREDENTIALS_DIR)/aks_credentials.json
TEST_CREDENTIALS_JSON ?= $(TEST_CREDENTIALS_DIR)/credentials.json
TEST_LOGANALYTICS_JSON ?= $(TEST_CREDENTIALS_DIR)/loganalytics.json
export TEST_CREDENTIALS_JSON TEST_LOGANALYTICS_JSON
export TEST_CREDENTIALS_JSON TEST_LOGANALYTICS_JSON TEST_AKS_CREDENTIALS_JSON

VERSION ?= v1.5.1
REGISTRY ?= ghcr.io
Expand Down Expand Up @@ -90,10 +91,11 @@ clean:
## Tests
## --------------------------------------

.PHONY: test
test:
.PHONY: unit-tests
test: testauth
@echo running tests
LOCATION=$(LOCATION) AZURE_AUTH_LOCATION=$(TEST_CREDENTIALS_JSON) \
LOCATION=$(LOCATION) AKS_CREDENTIAL_LOCATION=$(TEST_AKS_CREDENTIALS_JSON) \
AZURE_AUTH_LOCATION=$(TEST_CREDENTIALS_JSON) \
LOG_ANALYTICS_AUTH_LOCATION=$(TEST_LOGANALYTICS_JSON) \
go test -v $(shell go list ./... | grep -v /e2e) -race -coverprofile=coverage.out -covermode=atomic

Expand Down Expand Up @@ -141,13 +143,18 @@ fmt: $(GOIMPORTS) ## Run go fmt against code.
$(GOIMPORTS) -w $$(go list -f {{.Dir}} ./...)

.PHONY: testauth
testauth: test-cred-json test-loganalytics-json
testauth: test-cred-json test-aks-cred-json test-loganalytics-json

test-cred-json:
@echo Building test credentials
chmod a+x hack/ci/create_credentials.sh
hack/ci/create_credentials.sh

test-aks-cred-json:
@echo Building test AKS credentials
chmod a+x hack/ci/create_aks_credentials.sh
hack/ci/create_aks_credentials.sh

test-loganalytics-json:
@echo Building log analytics credentials
chmod a+x hack/ci/create_loganalytics_auth.sh
Expand Down
21 changes: 21 additions & 0 deletions hack/ci/create_aks_credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e -u

mkdir -p $(dirname "${TEST_AKS_CREDENTIALS_JSON}")

# This will build the AKS credentials during the CI
cat <<EOF > "${TEST_AKS_CREDENTIALS_JSON}"
{
"cloud": "AzurePublicCloud",
"tenantId": "######-###-####-####-######",
"subscriptionId": "######-###-####-####-######",
"aadClientId": "msi",
"aadClientSecret": "msi",
"resourceGroup": "######-###-####-####-######",
"location": "centralus",
"vnetName": "#####",
"vnetResourceGroup": "######-###-####-####-######",
"userAssignedIdentityID": "######-###-####-####-######"
}
EOF
20 changes: 10 additions & 10 deletions hack/ci/create_credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ mkdir -p $(dirname "${TEST_CREDENTIALS_JSON}")
# This will build the credentials during the CI
cat <<EOF > "${TEST_CREDENTIALS_JSON}"
{
"clientId": "$clientId",
"clientSecret": "$clientSecret",
"subscriptionId": "$subscriptionId",
"tenantId": "$tenantId",
"activeDirectoryEndpointUrl": "$activeDirectoryEndpointUrl",
"resourceManagerEndpointUrl": "$resourceManagerEndpointUrl",
"activeDirectoryGraphResourceId": "$activeDirectoryGraphResourceId",
"sqlManagementEndpointUrl": "$sqlManagementEndpointUrl",
"galleryEndpointUrl": "$galleryEndpointUrl",
"managementEndpointUrl": "$managementEndpointUrl"
"clientId": "######-###-####-####-######",
"clientSecret": "######-###-####-####-######",
"subscriptionId": "######-###-####-####-######",
"tenantId": "######-###-####-####-######",
"activeDirectoryEndpointUrl": "######-###-####-####-######",
"resourceManagerEndpointUrl": "######-###-####-####-######",
"activeDirectoryGraphResourceId": "######-###-####-####-######",
"sqlManagementEndpointUrl": "######-###-####-####-######",
"galleryEndpointUrl": "######-###-####-####-######",
"managementEndpointUrl": "######-###-####-####-######"
}
EOF
4 changes: 2 additions & 2 deletions hack/ci/create_loganalytics_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mkdir -p $(dirname "${TEST_LOGANALYTICS_JSON}")
# This will build the log analytics credentials during CI
cat <<EOF > "${TEST_LOGANALYTICS_JSON}"
{
"workspaceID": "$omsworkspaceID",
"workspaceKey": "$omsworkspaceKey"
"workspaceId": "######-###-####-####-######",
"workspaceKey": "######-###-####-####-######"
}
EOF

0 comments on commit 604b142

Please sign in to comment.