Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCPIE-1244: Improve Identity-Specific Testing #810

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/810.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
Add GitHub Action to run identity-specific tests
```
46 changes: 46 additions & 0 deletions .github/workflows/test-identity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run Identity Tests on Identity Code Changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Can this be extended to all the domains? As in run secrets test when those are changed? I had created ticket for this https://hashicorp.atlassian.net/browse/HCPF-1722

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manish-hashicorp
Yes! It can be extended manually for sure if each team wants to add their own step to this workflow. If we wanted a more autonomous solution, we might have to spend a bit more time on it.

Roughly speaking, we could do the following:

  • Get a listing of all changed files in Git. Parse the list to only show the modified directories.
  • Get a recursive listing of all directories within ./internal
  • Loop through the lists and mark which directories to run tests for
  • Loop again and actually run the tests with the changed files using make testacc-ci TEST=DIRECTORY_NAME

This will be out of scope for this specific ticket since it will require some more testing, but with that being said, I'm happy to update the ticket you posted with my findings. That way, whoever picks it up will have a head start on how to complete the work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Please do add information in that ticket.


on:
pull_request:
paths:
- 'internal/provider/iam/**'

jobs:
identity_tests:
name: Run identity specific tests
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
cache: true
go-version-file: 'go.mod'
cache-dependency-path: go.sum
id: go

- name: Run 'go mod tidy' and check for differences
run: |
make depscheck

- name: Get dependencies
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
go mod download

- name: Build
run: |
go build -v .

- name: Run identity tests
env:
HCP_API_HOST: ${{ secrets.HCP_API_HOST }}
HCP_AUTH_URL: ${{ secrets.HCP_AUTH_URL }}
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET }}
HCP_ORGANIZATION_ID: ${{ secrets.HCP_ORGANIZATION_ID }}
HCP_PROJECT_ID: ${{ secrets.HCP_PROJECT_ID }}
run: |
make testacc-ci TEST=./internal/provider/iam
15 changes: 15 additions & 0 deletions contributing/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/provider 539.112s
```

Running a specific test package:
```sh
$ make testacc TEST="./internal/provider/iam"
==> Checking that code complies with gofmt requirements...
golangci-lint run --config ./golangci-config.yml
TF_ACC=1 go test ./internal/provider/iam -v -timeout 360m -parallel=10
=== RUN TestAccGroupDataSource
--- PASS: TestAccGroupDataSource (8.69s)
...
=== RUN TestAccWorkloadIdentityProviderResource
--- PASS: TestAccWorkloadIdentityProviderResource (11.67s)
PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/provider/iam 125.260s
```

Entire resource test suites can be targeted by using the naming convention to
write the regular expression.

Expand Down