Skip to content

Commit

Permalink
test: run integration tests with different tags in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
PengyuanZhao committed Feb 27, 2024
1 parent e1c8162 commit 8704e41
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 61 deletions.
95 changes: 56 additions & 39 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ on:
- main

jobs:
run-tests:
run-linting-and-unit-tests:
runs-on: ubuntu-latest
steps:
# To wait for the existing test-build run to complete
- name: Turnstyle
uses: softprops/turnstyle@v1
with:
same-branch-only: false
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}

- name: Checkout repository
uses: actions/checkout@v4
with:
Expand All @@ -29,7 +21,7 @@ jobs:
with:
go-version: 1.21.x

- name: Run linting tests
- name: Run linting
id: update
run: |
make prepare
Expand All @@ -41,6 +33,58 @@ jobs:
run: |
make coverage-ci
# TODO Display test report

# - name: Notify Slack on Failure
# uses: slackapi/[email protected]
# if: failure()
# with:
# payload: |
# {
# "attachments": [
# {
# "color": "#E92020",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "@oncall-growth-eng! There has been a failure that needs your attention. :rotating_light:\n*GitHub Workflow Failure*\ngo-sdk/test-build\n*Workflow Run*\n https://github.com/lacework/go-sdk/actions/runs/${{ github.run_id }}"
# }
# }
# ]
# }
# ]
# }
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_GROWTH_ENG_ALERTS }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

run-integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
# To run integration tests with different tags in parallel
index: [0, 1, 2]
steps:
# To wait for the existing test-build run to complete to avoid running same integration tests at the same time
- name: Turnstyle
uses: softprops/turnstyle@v1
with:
same-branch-only: false
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}

- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x

- name: Build cross-platform binaries
run: |
make build-cli-cross-platform
Expand All @@ -55,37 +99,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y vim
make integration-only
# TODO Display test report

- name: Notify Slack on Failure
uses: slackapi/[email protected]
if: failure()
with:
payload: |
{
"attachments": [
{
"color": "#E92020",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "@oncall-growth-eng! There has been a failure that needs your attention. :rotating_light:\n*GitHub Workflow Failure*\ngo-sdk/test-build\n*Workflow Run*\n https://github.com/lacework/go-sdk/actions/runs/${{ github.run_id }}"
}
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_GROWTH_ENG_ALERTS }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
make integration-only-subset index=${{ matrix.index }}
trigger-release:
needs: run-tests
needs: [run-linting-and-unit-tests, run-integration-tests]
if: github.ref_name == 'main'
runs-on: ubuntu-latest
steps:
Expand Down
57 changes: 35 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ GOFLAGS=-mod=vendor
CGO_ENABLED?=0
export GOFLAGS GO_LDFLAGS CGO_ENABLED

INTEGRATION_TEST_TAGS=account \
agent_token \
alert \
alert_rule \
alert_channel \
alert_profile \
agent \
configure \
cloud_account \
container_registry \
query \
policy \
help \
version \
generation \
compliance \
team_member \
vulnerability \
report_definitions \
component \
resource_groups

.PHONY: help
help:
@echo "-------------------------------------------------------------------"
Expand Down Expand Up @@ -58,28 +80,19 @@ integration-generation-only: ## Run integration tests

.PHONY: integration-only
integration-only: install-tools ## Run integration tests
PATH="$(PWD)/bin:${PATH}" gotestsum -f testname -- -v github.com/lacework/go-sdk/integration -timeout 30m -tags="\
account \
agent_token \
alert \
alert_rule \
alert_channel \
alert_profile \
agent \
configure \
cloud_account \
container_registry \
query \
policy \
help \
version \
generation \
compliance \
team_member \
vulnerability \
report_definitions \
component \
resource_groups" -run=$(regex)
PATH="$(PWD)/bin:${PATH}" gotestsum -f testname -- -v github.com/lacework/go-sdk/integration -timeout 30m \
-tags="$(INTEGRATION_TEST_TAGS)" -run=$(regex)

.PHONY: integration-only-subset
integration-only-subset: install-tools ## Run a subset of integration tests
$(eval START := $(shell echo 1+$(index)*7 | bc))
$(eval END := $(shell echo 7+$(index)*7 | bc))
$(eval LENGTH := ${words $(INTEGRATION_TEST_TAGS)})
if [ ${START} -le ${LENGTH} ]; then \
PATH="$(PWD)/bin:${PATH}" gotestsum -f testname -- -v github.com/lacework/go-sdk/integration -timeout 30m \
-tags="${wordlist $(START), $(END), $(INTEGRATION_TEST_TAGS)}" -run=$(regex) \
exit 1; \
fi

.PHONY: integration-lql
integration-lql: build-cli-cross-platform integration-lql-only ## Build and run lql integration tests
Expand Down

0 comments on commit 8704e41

Please sign in to comment.