Skip to content

Commit

Permalink
chore: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed May 7, 2024
1 parent 4bb12d0 commit 2b03ceb
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 37 deletions.
64 changes: 35 additions & 29 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
push:
branches: [main]
pull_request:
schedule:
# Cron executes at 0800, 1200 1600 (8am, 12pm, 4pm)
- cron: "0 8,12,16 * * 1-5"
# schedule:
# # Cron executes at 0800, 1200 1600 (8am, 12pm, 4pm)
# - cron: "0 8,12,16 * * 1-5"

jobs:
test-integration:
runs-on: ubuntu-latest
steps:
# - name: Install Go
# uses: actions/setup-go@v4
# with:
# go-version: 1.19.x
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.19.x

# - name: Add GOBIN to PATH
# run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand All @@ -33,7 +33,6 @@ jobs:
# restore-keys: |
# ${{ runner.os }}-go-


# - name: Integration Tests
# if: github.event.pull_request.head.repo.full_name == github.repository
# run: make test-integration cover-report
Expand All @@ -55,25 +54,32 @@ jobs:
# INTEGRATION_TESTING_AZURE_SUBSCRIPTION_ID: ${{ secrets.INTEGRATION_TESTING_AZURE_SUBSCRIPTION_ID }}
# INTEGRATION_TESTING_AZURE_TENANT_ID: ${{ secrets.INTEGRATION_TESTING_AZURE_TENANT_ID }}

- name: Sent test report to Slack
id: slack
uses: slackapi/[email protected]
with:
# Uses Slack's Block Kit to build the message
payload: |
{
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
# - name: Create test failure report
# id: testFailureReport
# run: |
# go install github.com/mfridman/tparse@latest
# make test-failure-report
# tparse -file=coverage/integration.failures -format=markdown >> "$GITHUB_OUTPUT"

# - name: Send test failures report to Slack
# id: slack
# uses: slackapi/[email protected]
# with:
# # Uses Slack's Block Kit to build the message
# payload: |
# {
# "text": "New Relic Terraform Provider Test Failures",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "${{ steps.testFailureReport.outputs }}"
# }
# }
# ]
# }
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

64 changes: 60 additions & 4 deletions .github/workflows/test_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,65 @@ jobs:
${{ runner.os }}-go-
- name: Unit Tests
run: make test-unit cover-report
id: unit-tests
run: |
make test-unit cover-report
- name: Report unit test coverage via Codecov
uses: codecov/codecov-action@v3
- name: Create test failure report
id: test-failure-report
if: ${{ failure() }}
run: |
go install github.com/mfridman/tparse@latest
make test-failure-report
tparse -file=coverage/unit.failures -format=markdown > coverage/unit.md
- name: Prepare multiline test report
id: payload
shell: bash
if: ${{ always() }}
run: |
cat coverage/unit.md
payload=$(cat coverage/unit.md)
echo "test??"
echo $payload
echo "PAYLOAD<<EOF"$'\n'"$payload"$'\n'EOF >> "$GITHUB_OUTPUT"
- name: Failure report
id: failure-report
if: ${{ always() }}
run: |
echo "${{ steps.test-failure-report.outputs.PAYLOAD }}"
# - name: Report unit test coverage via Codecov
# uses: codecov/codecov-action@v3
# with:
# files: ./coverage/coverage.out

- name: Send test failures report to Slack
id: slack
if: ${{ always() }}
uses: slackapi/[email protected]
with:
files: ./coverage/coverage.out
# Uses Slack's Block Kit to build the message
payload: |
{
"text": "New Relic Terraform Provider Test Failures",
"blocks": [
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": ${{ toJSON(steps.test-failure-report.outputs.PAYLOAD) }}
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
11 changes: 8 additions & 3 deletions build/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ test-only: test-unit test-integration
test-unit: tools
@echo "=== $(PROJECT_NAME) === [ test-unit ]: running unit tests..."
@mkdir -p $(COVERAGE_DIR)
@$(TEST_RUNNER) -f testname --junitfile $(COVERAGE_DIR)/unit.xml --packages "$(GO_PKGS)" \
@$(TEST_RUNNER) -f testname --junitfile $(COVERAGE_DIR)/unit.xml --packages "$(GO_PKGS)" --jsonfile $(COVERAGE_DIR)/unit.report \
-- -v -parallel 10 -tags=unit $(TEST_ARGS) -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/unit.tmp

test-integration: tools
@echo "=== $(PROJECT_NAME) === [ test-integration ]: running integration tests..."
@mkdir -p $(COVERAGE_DIR)
@TF_ACC=1 $(TEST_RUNNER) -f testname --junitfile $(COVERAGE_DIR)/integration.xml --rerun-fails=1 --packages "$(GO_PKGS)" \
-- -v -parallel 8 -tags=integration $(TEST_ARGS) -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/integration.tmp \
@TF_ACC=1 $(TEST_RUNNER) -f testname --junitfile $(COVERAGE_DIR)/integration.xml --rerun-fails=1 --packages "$(GO_PKGS)" --jsonfile $(COVERAGE_DIR)/integration.report \
-- -v -parallel 10 -tags=integration $(TEST_ARGS) -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/integration.tmp \
-timeout 120m -ldflags=$(LDFLAGS_TEST)

test-failure-report: tools
@echo "=== $(PROJECT_NAME) === [ test-report-failed ]: generating report..."
@mkdir -p $(COVERAGE_DIR)
./scripts/test-failure-report.sh

#
# Coverage
#
Expand Down
2 changes: 1 addition & 1 deletion newrelic/provider_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestBuildUserAgentStringWithDefaultServiceName(t *testing.T) {
tfUA := "HashiCorp Terraform/1.3.5 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1"

result := buildUserAgentString(tfUA, getUserAgentServiceName(), ProviderVersion)
require.Contains(t, result, " terraform-provider-newrelic/dev")
require.Contains(t, result, " terraform-provider-newrelic/dev---fixthisbcitsatest")
}

func TestBuildUserAgentStringWithCustomServiceName(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions scripts/test-failure-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if ! [ -f ./coverage/integration.report ]; then
echo "File coverage/integration.report does not exist. Skipping."
else
echo "Creating integration test failures report..."
grep 'FAIL:\|FAIL\|Error:\|error:' coverage/integration.report > coverage/integration.failures
fi

if ! [ -f ./coverage/unit.report ]; then
echo "File coverage/unit.report does not exist. Skipping."
else
grep 'FAIL:\|FAIL\|Error:\|error:' coverage/unit.report > coverage/unit.failures
fi

0 comments on commit 2b03ceb

Please sign in to comment.