Skip to content

Commit 04dd8d1

Browse files
committed
ci: Fix simplify tests of docker repo with pro-feature subdomain
1 parent 025ac98 commit 04dd8d1

6 files changed

+58
-428
lines changed

internal/services/repository/data_source_repository_docker_group_test.go

+7-57
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ data "nexus_repository_docker_group" "acceptance" {
2020
}
2121

2222
func TestAccDataSourceRepositoryDockerGroup(t *testing.T) {
23-
repoHosted := testAccResourceRepositoryDockerHosted()
23+
nameHosted := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
24+
nameGroup := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
25+
repoHosted := testAccResourceRepositoryDockerHosted(nameHosted)
2426
repoGroup := repository.DockerGroupRepository{
25-
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)),
27+
Name: nameGroup,
2628
Online: true,
2729
Storage: repository.Storage{
2830
BlobStoreName: "default",
@@ -36,62 +38,10 @@ func TestAccDataSourceRepositoryDockerGroup(t *testing.T) {
3638
MemberNames: []string{repoHosted.Name},
3739
},
3840
}
39-
dataSourceName := "data.nexus_repository_docker_group.acceptance"
40-
41-
resource.Test(t, resource.TestCase{
42-
PreCheck: func() { acceptance.AccPreCheck(t) },
43-
Providers: acceptance.TestAccProviders,
44-
Steps: []resource.TestStep{
45-
{
46-
Config: testAccResourceRepositoryDockerHostedConfig(repoHosted) + testAccResourceRepositoryDockerGroupConfig(repoGroup) + testAccDataSourceRepositoryDockerGroupConfig(),
47-
Check: resource.ComposeTestCheckFunc(
48-
resource.ComposeAggregateTestCheckFunc(
49-
resource.ComposeAggregateTestCheckFunc(
50-
resource.TestCheckResourceAttr(dataSourceName, "id", repoGroup.Name),
51-
resource.TestCheckResourceAttr(dataSourceName, "name", repoGroup.Name),
52-
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repoGroup.Online)),
53-
),
54-
resource.ComposeAggregateTestCheckFunc(
55-
resource.TestCheckResourceAttr(dataSourceName, "docker.#", "1"),
56-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.force_basic_auth", strconv.FormatBool(repoGroup.Docker.ForceBasicAuth)),
57-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.v1_enabled", strconv.FormatBool(repoGroup.Docker.V1Enabled)),
58-
),
59-
resource.ComposeAggregateTestCheckFunc(
60-
resource.TestCheckResourceAttr(dataSourceName, "storage.#", "1"),
61-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repoGroup.Storage.BlobStoreName),
62-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repoGroup.Storage.StrictContentTypeValidation)),
63-
resource.TestCheckResourceAttr(dataSourceName, "group.#", "1"),
64-
resource.TestCheckResourceAttr(dataSourceName, "group.0.member_names.#", "1"),
65-
resource.TestCheckResourceAttr(dataSourceName, "group.0.member_names.0", repoGroup.Group.MemberNames[0]),
66-
),
67-
),
68-
),
69-
},
70-
},
71-
})
72-
}
73-
74-
func TestAccProDataSourceRepositoryDockerGroup(t *testing.T) {
75-
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" {
76-
t.Skip("Skipping Nexus Pro Tests")
77-
}
78-
repoHosted := testAccProResourceRepositoryDockerHosted()
79-
repoGroup := repository.DockerGroupRepository{
80-
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)),
81-
Online: true,
82-
Storage: repository.Storage{
83-
BlobStoreName: "default",
84-
StrictContentTypeValidation: false,
85-
},
86-
Docker: repository.Docker{
87-
ForceBasicAuth: true,
88-
V1Enabled: true,
89-
Subdomain: repoHosted.Subdomain,
90-
},
91-
Group: repository.GroupDeploy{
92-
MemberNames: []string{repoHosted.Name},
93-
},
41+
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "false" {
42+
repoGroup.Docker.Subdomain = &nameGroup
9443
}
44+
9545
dataSourceName := "data.nexus_repository_docker_group.acceptance"
9646

9747
resource.Test(t, resource.TestCase{

internal/services/repository/data_source_repository_docker_hosted_test.go

+3-41
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,7 @@ data "nexus_repository_docker_hosted" "acceptance" {
1919
}`
2020
}
2121

22-
func TestAccDataSourceRepositoryDockerHosted(t *testing.T) {
23-
repo := repository.DockerHostedRepository{
24-
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)),
25-
Online: true,
26-
Storage: repository.HostedStorage{
27-
BlobStoreName: "default",
28-
StrictContentTypeValidation: false,
29-
},
30-
Docker: repository.Docker{
31-
ForceBasicAuth: true,
32-
V1Enabled: true,
33-
},
34-
}
35-
dataSourceName := "data.nexus_repository_docker_hosted.acceptance"
36-
37-
resource.Test(t, resource.TestCase{
38-
PreCheck: func() { acceptance.AccPreCheck(t) },
39-
Providers: acceptance.TestAccProviders,
40-
Steps: []resource.TestStep{
41-
{
42-
Config: testAccResourceRepositoryDockerHostedConfig(repo) + testAccDataSourceRepositoryDockerHostedConfig(),
43-
Check: resource.ComposeTestCheckFunc(
44-
resource.ComposeAggregateTestCheckFunc(
45-
resource.TestCheckResourceAttr(dataSourceName, "id", repo.Name),
46-
resource.TestCheckResourceAttr(dataSourceName, "name", repo.Name),
47-
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repo.Online)),
48-
resource.TestCheckResourceAttr(dataSourceName, "docker.#", "1"),
49-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.force_basic_auth", strconv.FormatBool(repo.Docker.ForceBasicAuth)),
50-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.v1_enabled", strconv.FormatBool(repo.Docker.V1Enabled)),
51-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repo.Storage.BlobStoreName),
52-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repo.Storage.StrictContentTypeValidation)),
53-
),
54-
),
55-
},
56-
},
57-
})
58-
}
59-
6022
func TestAccProDataSourceRepositoryDockerHosted(t *testing.T) {
61-
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" {
62-
t.Skip("Skipping Nexus Pro Tests")
63-
}
6423
name := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
6524
repo := repository.DockerHostedRepository{
6625
Name: name,
@@ -75,6 +34,9 @@ func TestAccProDataSourceRepositoryDockerHosted(t *testing.T) {
7534
Subdomain: tools.GetStringPointer(name),
7635
},
7736
}
37+
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "false" {
38+
repo.Docker.Subdomain = &name
39+
}
7840
dataSourceName := "data.nexus_repository_docker_hosted.acceptance"
7941

8042
resource.Test(t, resource.TestCase{

internal/services/repository/data_source_repository_docker_proxy_test.go

+15-74
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,9 @@ data "nexus_repository_docker_proxy" "acceptance" {
1919
}`
2020
}
2121

22-
func TestAccDataSourceRepositoryDockerProxy(t *testing.T) {
23-
repoUsingDefaults := repository.DockerProxyRepository{
24-
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)),
25-
Online: true,
26-
Docker: repository.Docker{
27-
ForceBasicAuth: true,
28-
V1Enabled: true,
29-
},
30-
DockerProxy: repository.DockerProxy{
31-
IndexType: repository.DockerProxyIndexTypeHub,
32-
},
33-
Proxy: repository.Proxy{
34-
RemoteURL: "https://registry-1.docker.io",
35-
},
36-
Storage: repository.Storage{
37-
BlobStoreName: "default",
38-
StrictContentTypeValidation: true,
39-
},
40-
}
41-
42-
dataSourceName := "data.nexus_repository_docker_proxy.acceptance"
43-
44-
resource.Test(t, resource.TestCase{
45-
PreCheck: func() { acceptance.AccPreCheck(t) },
46-
Providers: acceptance.TestAccProviders,
47-
Steps: []resource.TestStep{
48-
{
49-
Config: testAccResourceRepositoryDockerProxyConfig(repoUsingDefaults) + testAccDataSourceRepositoryDockerProxyConfig(),
50-
Check: resource.ComposeTestCheckFunc(
51-
resource.ComposeAggregateTestCheckFunc(
52-
resource.TestCheckResourceAttr(dataSourceName, "id", repoUsingDefaults.Name),
53-
resource.TestCheckResourceAttr(dataSourceName, "name", repoUsingDefaults.Name),
54-
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repoUsingDefaults.Online)),
55-
),
56-
resource.ComposeAggregateTestCheckFunc(
57-
resource.TestCheckResourceAttr(dataSourceName, "docker.#", "1"),
58-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.force_basic_auth", strconv.FormatBool(repoUsingDefaults.Docker.ForceBasicAuth)),
59-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.v1_enabled", strconv.FormatBool(repoUsingDefaults.Docker.V1Enabled)),
60-
resource.TestCheckResourceAttr(dataSourceName, "docker_proxy.#", "1"),
61-
resource.TestCheckResourceAttr(dataSourceName, "docker_proxy.0.index_type", string(repoUsingDefaults.DockerProxy.IndexType)),
62-
),
63-
resource.ComposeAggregateTestCheckFunc(
64-
resource.TestCheckResourceAttr(dataSourceName, "http_client.#", "1"),
65-
resource.TestCheckResourceAttr(dataSourceName, "http_client.0.authentication.#", "0"),
66-
resource.TestCheckResourceAttr(dataSourceName, "http_client.0.connection.#", "1"),
67-
resource.TestCheckResourceAttr(dataSourceName, "negative_cache.#", "1"),
68-
resource.TestCheckResourceAttr(dataSourceName, "proxy.#", "1"),
69-
resource.TestCheckResourceAttr(dataSourceName, "proxy.0.remote_url", repoUsingDefaults.Proxy.RemoteURL),
70-
resource.TestCheckResourceAttr(dataSourceName, "storage.#", "1"),
71-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repoUsingDefaults.Storage.BlobStoreName),
72-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repoUsingDefaults.Storage.StrictContentTypeValidation)),
73-
),
74-
),
75-
},
76-
},
77-
})
78-
}
79-
8022
func TestAccProDataSourceRepositoryDockerProxy(t *testing.T) {
81-
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" {
82-
t.Skip("Skipping Nexus Pro Tests")
83-
}
8423
name := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
85-
repoUsingDefaults := repository.DockerProxyRepository{
24+
repo := repository.DockerProxyRepository{
8625
Name: name,
8726
Online: true,
8827
Docker: repository.Docker{
@@ -101,39 +40,41 @@ func TestAccProDataSourceRepositoryDockerProxy(t *testing.T) {
10140
StrictContentTypeValidation: true,
10241
},
10342
}
104-
43+
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "false" {
44+
repo.Docker.Subdomain = &name
45+
}
10546
dataSourceName := "data.nexus_repository_docker_proxy.acceptance"
10647

10748
resource.Test(t, resource.TestCase{
10849
PreCheck: func() { acceptance.AccPreCheck(t) },
10950
Providers: acceptance.TestAccProviders,
11051
Steps: []resource.TestStep{
11152
{
112-
Config: testAccResourceRepositoryDockerProxyConfig(repoUsingDefaults) + testAccDataSourceRepositoryDockerProxyConfig(),
53+
Config: testAccResourceRepositoryDockerProxyConfig(repo) + testAccDataSourceRepositoryDockerProxyConfig(),
11354
Check: resource.ComposeTestCheckFunc(
11455
resource.ComposeAggregateTestCheckFunc(
115-
resource.TestCheckResourceAttr(dataSourceName, "id", repoUsingDefaults.Name),
116-
resource.TestCheckResourceAttr(dataSourceName, "name", repoUsingDefaults.Name),
117-
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repoUsingDefaults.Online)),
56+
resource.TestCheckResourceAttr(dataSourceName, "id", repo.Name),
57+
resource.TestCheckResourceAttr(dataSourceName, "name", repo.Name),
58+
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repo.Online)),
11859
),
11960
resource.ComposeAggregateTestCheckFunc(
12061
resource.TestCheckResourceAttr(dataSourceName, "docker.#", "1"),
121-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.force_basic_auth", strconv.FormatBool(repoUsingDefaults.Docker.ForceBasicAuth)),
122-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.v1_enabled", strconv.FormatBool(repoUsingDefaults.Docker.V1Enabled)),
123-
resource.TestCheckResourceAttr(dataSourceName, "docker.0.subdomain", string(*repoUsingDefaults.Docker.Subdomain)),
62+
resource.TestCheckResourceAttr(dataSourceName, "docker.0.force_basic_auth", strconv.FormatBool(repo.Docker.ForceBasicAuth)),
63+
resource.TestCheckResourceAttr(dataSourceName, "docker.0.v1_enabled", strconv.FormatBool(repo.Docker.V1Enabled)),
64+
resource.TestCheckResourceAttr(dataSourceName, "docker.0.subdomain", string(*repo.Docker.Subdomain)),
12465
resource.TestCheckResourceAttr(dataSourceName, "docker_proxy.#", "1"),
125-
resource.TestCheckResourceAttr(dataSourceName, "docker_proxy.0.index_type", string(repoUsingDefaults.DockerProxy.IndexType)),
66+
resource.TestCheckResourceAttr(dataSourceName, "docker_proxy.0.index_type", string(repo.DockerProxy.IndexType)),
12667
),
12768
resource.ComposeAggregateTestCheckFunc(
12869
resource.TestCheckResourceAttr(dataSourceName, "http_client.#", "1"),
12970
resource.TestCheckResourceAttr(dataSourceName, "http_client.0.authentication.#", "0"),
13071
resource.TestCheckResourceAttr(dataSourceName, "http_client.0.connection.#", "1"),
13172
resource.TestCheckResourceAttr(dataSourceName, "negative_cache.#", "1"),
13273
resource.TestCheckResourceAttr(dataSourceName, "proxy.#", "1"),
133-
resource.TestCheckResourceAttr(dataSourceName, "proxy.0.remote_url", repoUsingDefaults.Proxy.RemoteURL),
74+
resource.TestCheckResourceAttr(dataSourceName, "proxy.0.remote_url", repo.Proxy.RemoteURL),
13475
resource.TestCheckResourceAttr(dataSourceName, "storage.#", "1"),
135-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repoUsingDefaults.Storage.BlobStoreName),
136-
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repoUsingDefaults.Storage.StrictContentTypeValidation)),
76+
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repo.Storage.BlobStoreName),
77+
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repo.Storage.StrictContentTypeValidation)),
13778
),
13879
),
13980
},

internal/services/repository/resource_repository_docker_group_test.go

+20-34
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1616
)
1717

18-
func testAccResourceRepositoryDockerGroup() repository.DockerGroupRepository {
18+
func testAccResourceRepositoryDockerGroup(name string) repository.DockerGroupRepository {
1919
return repository.DockerGroupRepository{
20-
Name: fmt.Sprintf("test-repo-%s", acctest.RandString(10)),
20+
Name: name,
2121
Online: true,
2222
Docker: repository.Docker{
2323
ForceBasicAuth: true,
@@ -35,28 +35,6 @@ func testAccResourceRepositoryDockerGroup() repository.DockerGroupRepository {
3535
}
3636
}
3737

38-
func testAccProResourceRepositoryDockerGroup() repository.DockerGroupRepository {
39-
subdomain := fmt.Sprintf("test-repo-%s", acctest.RandString(10))
40-
return repository.DockerGroupRepository{
41-
Name: fmt.Sprintf("test-repo-%s", acctest.RandString(10)),
42-
Online: true,
43-
Docker: repository.Docker{
44-
ForceBasicAuth: true,
45-
HTTPPort: tools.GetIntPointer(rand.Intn(999) + 32000),
46-
HTTPSPort: tools.GetIntPointer(rand.Intn(999) + 33000),
47-
V1Enabled: false,
48-
Subdomain: tools.GetStringPointer(subdomain),
49-
},
50-
Storage: repository.Storage{
51-
BlobStoreName: "default",
52-
StrictContentTypeValidation: true,
53-
},
54-
Group: repository.GroupDeploy{
55-
MemberNames: []string{},
56-
},
57-
}
58-
}
59-
6038
func testAccResourceRepositoryDockerGroupConfig(repo repository.DockerGroupRepository) string {
6139
buf := &bytes.Buffer{}
6240
resourceRepositoryDockerGroupTemplate := template.Must(template.New("DockerGroupRepository").Funcs(acceptance.TemplateFuncMap).Parse(acceptance.TemplateStringRepositoryDockerGroup))
@@ -67,8 +45,15 @@ func testAccResourceRepositoryDockerGroupConfig(repo repository.DockerGroupRepos
6745
}
6846

6947
func TestAccResourceRepositoryDockerGroup(t *testing.T) {
70-
repoHosted := testAccResourceRepositoryDockerHosted()
71-
repoGroup := testAccResourceRepositoryDockerGroup()
48+
nameHosted := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
49+
nameGroup := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
50+
51+
repoHosted := testAccResourceRepositoryDockerHosted(nameHosted)
52+
repoGroup := testAccResourceRepositoryDockerGroup(nameGroup)
53+
54+
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "false" {
55+
repoGroup.Docker.Subdomain = &nameGroup
56+
}
7257
repoGroup.Group.MemberNames = append(repoGroup.Group.MemberNames, repoHosted.Name)
7358

7459
resourceName := "nexus_repository_docker_group.acceptance"
@@ -114,16 +99,17 @@ func TestAccResourceRepositoryDockerGroup(t *testing.T) {
11499
}
115100

116101
func TestAccProResourceRepositoryDockerGroup(t *testing.T) {
117-
if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" {
118-
t.Skip("Skipping Nexus Pro Tests")
119-
}
120-
repoHosted := testAccProResourceRepositoryDockerHosted()
121-
repoGroup := testAccProResourceRepositoryDockerGroup()
102+
nameHosted := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
103+
nameGroup := fmt.Sprintf("acceptance-%s", acctest.RandString(10))
104+
105+
repoHosted := testAccResourceRepositoryDockerHosted(nameHosted)
106+
repoGroup := testAccResourceRepositoryDockerGroup(nameGroup)
122107
repoGroup.Group.MemberNames = append(repoGroup.Group.MemberNames, repoHosted.Name)
123108

109+
if tools.GetEnv("SKIP_PRO_TESTS", "false") != "true" {
110+
repoGroup.Docker.Subdomain = &nameGroup
111+
}
124112
writableMember := repoHosted.Name
125-
subdomain := string(*repoGroup.Docker.Subdomain)
126-
127113
repoGroup.Group.WritableMember = &writableMember
128114
resourceName := "nexus_repository_docker_group.acceptance"
129115

@@ -154,7 +140,7 @@ func TestAccProResourceRepositoryDockerGroup(t *testing.T) {
154140
resource.TestCheckResourceAttr(resourceName, "docker.0.http_port", strconv.Itoa(*repoGroup.Docker.HTTPPort)),
155141
resource.TestCheckResourceAttr(resourceName, "docker.0.https_port", strconv.Itoa(*repoGroup.Docker.HTTPSPort)),
156142
resource.TestCheckResourceAttr(resourceName, "docker.0.v1_enabled", strconv.FormatBool(repoGroup.Docker.V1Enabled)),
157-
resource.TestCheckResourceAttr(resourceName, "docker.0.subdomain", subdomain),
143+
resource.TestCheckResourceAttr(resourceName, "docker.0.subdomain", string(*repoGroup.Docker.Subdomain)),
158144
),
159145
),
160146
},

0 commit comments

Comments
 (0)