Skip to content

Commit cdfeeba

Browse files
committed
Revert "chore: remove unused test files"
This reverts commit a68b9a3.
1 parent ee9716f commit cdfeeba

File tree

9 files changed

+754
-0
lines changed

9 files changed

+754
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"context"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/api/errors"
25+
"k8s.io/apimachinery/pkg/types"
26+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
27+
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
31+
)
32+
33+
var _ = Describe("Account Controller", func() {
34+
Context("When reconciling a resource", func() {
35+
const resourceName = "test-resource"
36+
37+
ctx := context.Background()
38+
39+
typeNamespacedName := types.NamespacedName{
40+
Name: resourceName,
41+
Namespace: "default", // TODO(user):Modify as needed
42+
}
43+
account := &cloudflareoperatoriov1.Account{}
44+
45+
BeforeEach(func() {
46+
By("creating the custom resource for the Kind Account")
47+
err := k8sClient.Get(ctx, typeNamespacedName, account)
48+
if err != nil && errors.IsNotFound(err) {
49+
resource := &cloudflareoperatoriov1.Account{
50+
ObjectMeta: metav1.ObjectMeta{
51+
Name: resourceName,
52+
Namespace: "default",
53+
},
54+
// TODO(user): Specify other spec details if needed.
55+
}
56+
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
57+
}
58+
})
59+
60+
AfterEach(func() {
61+
// TODO(user): Cleanup logic after each test, like removing the resource instance.
62+
resource := &cloudflareoperatoriov1.Account{}
63+
err := k8sClient.Get(ctx, typeNamespacedName, resource)
64+
Expect(err).NotTo(HaveOccurred())
65+
66+
By("Cleanup the specific resource instance Account")
67+
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
68+
})
69+
It("should successfully reconcile the resource", func() {
70+
By("Reconciling the created resource")
71+
controllerReconciler := &AccountReconciler{
72+
Client: k8sClient,
73+
Scheme: k8sClient.Scheme(),
74+
}
75+
76+
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
77+
NamespacedName: typeNamespacedName,
78+
})
79+
Expect(err).NotTo(HaveOccurred())
80+
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81+
// Example: If you expect a certain status condition after reconciliation, verify it here.
82+
})
83+
})
84+
})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"context"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/api/errors"
25+
"k8s.io/apimachinery/pkg/types"
26+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
27+
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
31+
)
32+
33+
var _ = Describe("DNSRecord Controller", func() {
34+
Context("When reconciling a resource", func() {
35+
const resourceName = "test-resource"
36+
37+
ctx := context.Background()
38+
39+
typeNamespacedName := types.NamespacedName{
40+
Name: resourceName,
41+
Namespace: "default", // TODO(user):Modify as needed
42+
}
43+
dnsrecord := &cloudflareoperatoriov1.DNSRecord{}
44+
45+
BeforeEach(func() {
46+
By("creating the custom resource for the Kind DNSRecord")
47+
err := k8sClient.Get(ctx, typeNamespacedName, dnsrecord)
48+
if err != nil && errors.IsNotFound(err) {
49+
resource := &cloudflareoperatoriov1.DNSRecord{
50+
ObjectMeta: metav1.ObjectMeta{
51+
Name: resourceName,
52+
Namespace: "default",
53+
},
54+
// TODO(user): Specify other spec details if needed.
55+
}
56+
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
57+
}
58+
})
59+
60+
AfterEach(func() {
61+
// TODO(user): Cleanup logic after each test, like removing the resource instance.
62+
resource := &cloudflareoperatoriov1.DNSRecord{}
63+
err := k8sClient.Get(ctx, typeNamespacedName, resource)
64+
Expect(err).NotTo(HaveOccurred())
65+
66+
By("Cleanup the specific resource instance DNSRecord")
67+
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
68+
})
69+
It("should successfully reconcile the resource", func() {
70+
By("Reconciling the created resource")
71+
controllerReconciler := &DNSRecordReconciler{
72+
Client: k8sClient,
73+
Scheme: k8sClient.Scheme(),
74+
}
75+
76+
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
77+
NamespacedName: typeNamespacedName,
78+
})
79+
Expect(err).NotTo(HaveOccurred())
80+
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81+
// Example: If you expect a certain status condition after reconciliation, verify it here.
82+
})
83+
})
84+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
)
22+
23+
var _ = Describe("Ingress Controller", func() {
24+
Context("When reconciling a resource", func() {
25+
It("should successfully reconcile the resource", func() {
26+
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
27+
// Example: If you expect a certain status condition after reconciliation, verify it here.
28+
})
29+
})
30+
})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"context"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/api/errors"
25+
"k8s.io/apimachinery/pkg/types"
26+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
27+
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
31+
)
32+
33+
var _ = Describe("IP Controller", func() {
34+
Context("When reconciling a resource", func() {
35+
const resourceName = "test-resource"
36+
37+
ctx := context.Background()
38+
39+
typeNamespacedName := types.NamespacedName{
40+
Name: resourceName,
41+
Namespace: "default", // TODO(user):Modify as needed
42+
}
43+
ip := &cloudflareoperatoriov1.IP{}
44+
45+
BeforeEach(func() {
46+
By("creating the custom resource for the Kind IP")
47+
err := k8sClient.Get(ctx, typeNamespacedName, ip)
48+
if err != nil && errors.IsNotFound(err) {
49+
resource := &cloudflareoperatoriov1.IP{
50+
ObjectMeta: metav1.ObjectMeta{
51+
Name: resourceName,
52+
Namespace: "default",
53+
},
54+
// TODO(user): Specify other spec details if needed.
55+
}
56+
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
57+
}
58+
})
59+
60+
AfterEach(func() {
61+
// TODO(user): Cleanup logic after each test, like removing the resource instance.
62+
resource := &cloudflareoperatoriov1.IP{}
63+
err := k8sClient.Get(ctx, typeNamespacedName, resource)
64+
Expect(err).NotTo(HaveOccurred())
65+
66+
By("Cleanup the specific resource instance IP")
67+
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
68+
})
69+
It("should successfully reconcile the resource", func() {
70+
By("Reconciling the created resource")
71+
controllerReconciler := &IPReconciler{
72+
Client: k8sClient,
73+
Scheme: k8sClient.Scheme(),
74+
}
75+
76+
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
77+
NamespacedName: typeNamespacedName,
78+
})
79+
Expect(err).NotTo(HaveOccurred())
80+
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81+
// Example: If you expect a certain status condition after reconciliation, verify it here.
82+
})
83+
})
84+
})

internal/controller/suite_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"fmt"
21+
"path/filepath"
22+
"runtime"
23+
"testing"
24+
25+
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
27+
28+
"k8s.io/client-go/kubernetes/scheme"
29+
"k8s.io/client-go/rest"
30+
"sigs.k8s.io/controller-runtime/pkg/client"
31+
"sigs.k8s.io/controller-runtime/pkg/envtest"
32+
logf "sigs.k8s.io/controller-runtime/pkg/log"
33+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
34+
35+
networkingv1 "k8s.io/api/networking/v1"
36+
37+
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
38+
//+kubebuilder:scaffold:imports
39+
)
40+
41+
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
42+
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
43+
44+
var (
45+
cfg *rest.Config
46+
k8sClient client.Client
47+
testEnv *envtest.Environment
48+
)
49+
50+
func TestControllers(t *testing.T) {
51+
RegisterFailHandler(Fail)
52+
53+
RunSpecs(t, "Controller Suite")
54+
}
55+
56+
var _ = BeforeSuite(func() {
57+
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
58+
59+
By("bootstrapping test environment")
60+
testEnv = &envtest.Environment{
61+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
62+
ErrorIfCRDPathMissing: true,
63+
64+
// The BinaryAssetsDirectory is only required if you want to run the tests directly
65+
// without call the makefile target test. If not informed it will look for the
66+
// default path defined in controller-runtime which is /usr/local/kubebuilder/.
67+
// Note that you must have the required binaries setup under the bin directory to perform
68+
// the tests directly. When we run make test it will be setup and used automatically.
69+
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s",
70+
fmt.Sprintf("1.28.3-%s-%s", runtime.GOOS, runtime.GOARCH)),
71+
}
72+
73+
var err error
74+
// cfg is defined in this file globally.
75+
cfg, err = testEnv.Start()
76+
Expect(err).NotTo(HaveOccurred())
77+
Expect(cfg).NotTo(BeNil())
78+
79+
err = cloudflareoperatoriov1.AddToScheme(scheme.Scheme)
80+
Expect(err).NotTo(HaveOccurred())
81+
82+
err = networkingv1.AddToScheme(scheme.Scheme)
83+
Expect(err).NotTo(HaveOccurred())
84+
85+
//+kubebuilder:scaffold:scheme
86+
87+
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
88+
Expect(err).NotTo(HaveOccurred())
89+
Expect(k8sClient).NotTo(BeNil())
90+
})
91+
92+
var _ = AfterSuite(func() {
93+
By("tearing down the test environment")
94+
err := testEnv.Stop()
95+
Expect(err).NotTo(HaveOccurred())
96+
})

0 commit comments

Comments
 (0)