Skip to content

Commit 79ecd51

Browse files
authored
Merge pull request #1765 from jamielennox/error-if-missing
✨ Use ErrorIfCRDPathMissing in EnvTest
2 parents 3af7d23 + 0a5c604 commit 79ecd51

File tree

17 files changed

+37
-17
lines changed

17 files changed

+37
-17
lines changed

pkg/plugins/golang/v3/scaffolds/internal/templates/api/webhook_suitetest.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type WebhookSuite struct {
1717
file.BoilerplateMixin
1818
file.ResourceMixin
1919

20+
// todo: currently is not possible to know if an API was or not scaffolded. We can fix it when #1826 be addressed
21+
WireResource bool
22+
2023
// BaseDirectoryRelativePath define the Path for the base directory when it is multigroup
2124
BaseDirectoryRelativePath string
2225
}
@@ -162,7 +165,8 @@ var _ = BeforeSuite(func() {
162165
163166
By("bootstrapping test environment")
164167
testEnv = &envtest.Environment{
165-
CRDDirectoryPaths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "crd", "bases")},
168+
CRDDirectoryPaths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "crd", "bases")},
169+
ErrorIfCRDPathMissing: {{ .WireResource }},
166170
WebhookInstallOptions: envtest.WebhookInstallOptions{
167171
Paths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "webhook")},
168172
},

pkg/plugins/golang/v3/scaffolds/internal/templates/controllers/controller_suitetest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ var _ = BeforeSuite(func() {
165165
166166
By("bootstrapping test environment")
167167
testEnv = &envtest.Environment{
168-
CRDDirectoryPaths: []string{filepath.Join({{ .CRDDirectoryRelativePath }}, "config", "crd", "bases")},
168+
CRDDirectoryPaths: []string{filepath.Join({{ .CRDDirectoryRelativePath }}, "config", "crd", "bases")},
169+
ErrorIfCRDPathMissing: {{ .WireResource }},
169170
}
170171
171172
cfg, err := testEnv.Start()

testdata/project-v3-addon/controllers/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ var _ = BeforeSuite(func() {
5454

5555
By("bootstrapping test environment")
5656
testEnv = &envtest.Environment{
57-
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
57+
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
58+
ErrorIfCRDPathMissing: true,
5859
}
5960

6061
cfg, err := testEnv.Start()

testdata/project-v3-config/api/v1/webhook_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
7071
},

testdata/project-v3-config/controllers/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ var _ = BeforeSuite(func() {
5454

5555
By("bootstrapping test environment")
5656
testEnv = &envtest.Environment{
57-
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
57+
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
58+
ErrorIfCRDPathMissing: true,
5859
}
5960

6061
cfg, err := testEnv.Start()

testdata/project-v3-multigroup/apis/crew/v1/webhook_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
7071
},

testdata/project-v3-multigroup/apis/ship/v1/webhook_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
7071
},

testdata/project-v3-multigroup/apis/ship/v2alpha1/webhook_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
7071
},

testdata/project-v3-multigroup/apis/v1/webhook_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
7071
},

testdata/project-v3-multigroup/controllers/apps/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var _ = BeforeSuite(func() {
5252

5353
By("bootstrapping test environment")
5454
testEnv = &envtest.Environment{
55-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
55+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
56+
ErrorIfCRDPathMissing: false,
5657
}
5758

5859
cfg, err := testEnv.Start()

0 commit comments

Comments
 (0)