Skip to content

Commit 7b37445

Browse files
authored
tests: improvements to acceptance testing (#128)
- update repo tests to create image repos in an organization, not a personal namespace. this is a more common use-case. and we're trying to discourage people in-product from creating personal namespaces - add more docs on how to write new acceptance tests and run existing ones Signed-off-by: Nick Santos <nick.santos@docker.com>
1 parent d0825c9 commit 7b37445

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

CONTRIBUTING.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,27 @@ Note, when you run the `terraform plan` you should see a warning, this ensures t
5757
5858
Happy developing!
5959

60-
## Testing
60+
## Acceptance Testing
6161

62-
Run full test suite:
62+
WARNING: Acceptance tests run the provider with a real account against a real
63+
environment. They will create repositories, delete repositories, invite users to
64+
orgs, etc.
6365

64-
```shell
65-
make testacc
66+
Only run them with account credentials that are ok for testing!
67+
68+
### Adding a new test
69+
70+
If you're contributing a new test, set up your credentials:
71+
72+
```
73+
export DOCKER_USERNAME=[your-username]
74+
export DOCKER_PASSWORD=[your-password]
75+
export ACCTEST_DOCKER_ORG=[an-org-you-belong-to]
6676
```
6777

68-
Run a specific test(s):
78+
Then run:
6979

70-
```shell
80+
```
7181
make testacc TESTS=TestAccXXX
7282
```
7383

@@ -79,6 +89,36 @@ TF_ACC=1 go test ./... -v -count 1 -parallel 20 -timeout 120m -run TestAccXXX
7989

8090
where `TestAccXXX` is the testing function within the `_test.go` file.
8191

92+
New tests should create resources under the org namespace
93+
`envvar.AccTestOrganization`. See existing tests for examples.
94+
95+
### Running the full test suite
96+
97+
Only Docker employees can currently run the full acceptance suite,
98+
because they use the stage environment.
99+
100+
To run the tests on Github Actions on main, run:
101+
102+
```
103+
gh workflow run acctest.yaml
104+
```
105+
106+
To run it on a specific branch, run:
107+
108+
```
109+
gh workflow run acctest.yaml -f ref=[git-sha|branch-name]
110+
```
111+
112+
To run it locally, you will need credentials for our test account.
113+
The password is in the terraform-provider-docker 1password vault.
114+
115+
```
116+
export DOCKER_HUB_HOST=hub-stage.docker.com
117+
export DOCKER_USERNAME=dockerterraformacctest
118+
export DOCKER_PASSWORD=[password]
119+
make testacc
120+
```
121+
82122
## Environment Variables
83123

84124
```shell

internal/provider/resource_repository_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ package provider
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"testing"
2322

23+
"github.com/docker/terraform-provider-docker/internal/envvar"
2424
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
2525
"github.com/hashicorp/terraform-plugin-testing/terraform"
2626
)
2727

2828
func TestAccRepositoryResource(t *testing.T) {
29-
namespace := os.Getenv("DOCKER_USERNAME")
29+
namespace := envvar.GetWithDefault(envvar.AccTestOrganization)
3030
name := "example-repo" + randString(10)
3131
resource.Test(t, resource.TestCase{
3232
PreCheck: func() { testAccPreCheck(t) },
@@ -65,7 +65,7 @@ func TestAccRepositoryResource(t *testing.T) {
6565
}
6666

6767
func TestAccRepositoryResource_Upgrade(t *testing.T) {
68-
namespace := os.Getenv("DOCKER_USERNAME")
68+
namespace := envvar.GetWithDefault(envvar.AccTestOrganization)
6969
name := "example-repo" + randString(10)
7070
resource.Test(t, resource.TestCase{
7171
PreCheck: func() { testAccPreCheck(t) },
@@ -117,7 +117,7 @@ resource "docker_hub_repository" "test" {
117117
}
118118

119119
func TestAccRepositoryResourceImmutableTags(t *testing.T) {
120-
namespace := os.Getenv("DOCKER_USERNAME")
120+
namespace := envvar.GetWithDefault(envvar.AccTestOrganization)
121121
name := "immutable-repo" + randString(10)
122122
resource.Test(t, resource.TestCase{
123123
PreCheck: func() { testAccPreCheck(t) },

0 commit comments

Comments
 (0)