Skip to content

Commit

Permalink
Improve test functionality (#35)
Browse files Browse the repository at this point in the history
- Parameterize common test variables
- Support checkouts from forks on workflow_dispatch
- Cleanups to README formatting
  • Loading branch information
twelsh-aw authored Aug 27, 2024
1 parent 877ed21 commit 7c2f868
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/acctest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
type: string
required: false
default: '1.9.*'
ref:
description: 'The ref to checkout e.g the SHA of a fork in PR'
type: string
required: false
default: 'main'

jobs:
acctest:
Expand All @@ -17,6 +22,8 @@ jobs:
concurrency: acctest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-go@v5

Expand Down
49 changes: 36 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Contributing to Docker Terraform Provider

Thank you for considering contributing to the Docker Terraform Provider! We welcome contributions from everyone. To ensure a smooth process, please follow the guidelines below.
Thank you for considering contributing to the Docker Terraform Provider! We welcome contributions from everyone. To ensure a smooth process, please follow the guidelines below.

## Reporting Issues and Suggesting Enhancements

1. Before creating a new issue, please check if the issue has already been reported in the list of [existing issues](https://github.com/docker/terraform-provider-docker/issues)
2. If you don't find an existing issue, open a new one and fill out the template based on the issue type - it's important to provide as much detail as possible

## Making Code Contributions

1. Fork the repository
2. Check with the authors in an issue ticket before doing anything big
3. Contribute improvements or fixes using a [Pull Request](https://github.com/docker/terraform-provider-docker/pulls)
Expand All @@ -16,29 +18,39 @@ Thank you for considering contributing to the Docker Terraform Provider! We welc
7. When updating documentation, please see our guidance for documentation contributions (TODO)

## Local Development Setup
### Prerequisites:

### Prerequisites

- `make`, `git`, `bash`
- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.1
- [Go](https://golang.org/doc/install) >= 1.21
- [Go](https://golang.org/doc/install) >= 1.21
- Ensure your [GOPATH](http://golang.org/doc/code.html#GOPATH) is correctly setup, as well as adding `$GOPATH/bin` to your `$PATH`

1. Clone `terraform-provider-docker`
```

```shell
git clone https://github.com/docker/terraform-provider-docker
```

2. Install provider & setup `~/.terrraformrc` making `registry.terraform.io/docker/docker` reference your local installation
```

```shell
make local-build
```

3. Setup your Docker Hub username & password
```

```shell
export DOCKER_USERNAME=$(yourusername)
export DOCKER_PASSWORD=$(yourpassword)
```

4. Run an example build!
```

```shell
cd examples && terraform plan
```

Note, when you run the `terraform plan` you should see a warning, this ensures that you using the locally installed provider and not the publically available provider.

> │ Warning: Provider development overrides are in effect
Expand All @@ -48,27 +60,38 @@ Happy developing!
## Testing

Run full test suite:
```

```shell
make testacc
```

Run an individual test:
Run an specific test(s):

```shell
make testacc TESTS=TestAccXXX
```
TF_ACC=1 go test ./internal/provider -v -timeout 120m -run TestFuncName

which is equivalent to:

```shell
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -timeout 120m -run TestAccXXX
```
where `TestFuncName` is the testing function within the `_test.go` file.

where `TestFuncName` is the testing function within the `_test.go` file.

## Environment Variables
```

```shell
# enable debug logging
export TF_LOG=DEBUG
export TF_LOG_PATH="/PATH/TO/YOUR/LOG_FILE.log"
...
```

## Getting Help

If you have any questions or need assistance, please reach out to us through in the DTP Slack Channel (TODO)

# Thanks for Contributing!
## Thanks for Contributing

Your contributions help make the Docker Terraform Provider better for everyone. We appreciate your support and effort!
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
ACCTEST_COUNT ?= 1
ACCTEST_PARALLELISM ?= 20
ACCTEST_TIMEOUT ?= 120m

ifneq ($(origin TESTS), undefined)
RUNARGS = -run='$(TESTS)'
endif

# Default target
default: testacc

# Run acceptance tests
.PHONY: testacc
testacc:
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
TF_ACC=1 go test ./... -v -count $(ACCTEST_COUNT) -parallel $(ACCTEST_PARALLELISM) -timeout $(ACCTEST_TIMEOUT) $(RUNARGS) $(TESTARGS)

# Install the provider binary to GOBIN
.PHONY: install
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Docker Hub Terraform Provider

This project is used to manage Docker resources (such as repositories, teams, organization settings, and more) using Terraform. It allows users to define Docker infrastructure as code, integrating Docker services into their Terraform workflows. The Terraform Registry page for this provider can be found [here](https://registry.terraform.io/providers/docker/docker/).

> [!WARNING]
Expand All @@ -9,10 +10,11 @@ This project is used to manage Docker resources (such as repositories, teams, or
- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.1
- [Go](https://golang.org/doc/install) >= 1.21 (to build the provider plugin)

## Usage
## Usage

Below is a basic example of how to use the Docker services Terraform provider to create a Docker repository. Using `DOCKER_USERNAME` and `DOCKER_PASSWORD` as an environment variable, you can use the following code:

```
```hcl
terraform {
required_providers {
docker = {
Expand All @@ -31,17 +33,18 @@ resource "docker_repository" "example" {
}
```

## Contributing


## Contributing
We welcome contributions to the Docker services Terraform provider, detailed documentation for contributing & building the provider can be found [here](https://github.com/docker/terraform-provider-docker/blob/main/CONTRIBUTING.md)

## Roadmap

Our roadmap is managed through GitHub issues. You can view upcoming features and enhancements, as well as report bugs or request new features, by visiting our [issues page](https://github.com/docker/terraform-provider-docker/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen).

## Support

TODO: how much will we be supporting this & at what cadence?

## License

This project is licensed under the Apache 2.0 License. See the [LICENSE](https://github.com/docker/terraform-provider-docker/blob/main/LICENSE) file for more information.

0 comments on commit 7c2f868

Please sign in to comment.