@@ -32,7 +32,7 @@ import (
3232
3333 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
35- "github.com/cloudflare/cloudflare-go"
35+ cloudflare "github.com/cloudflare/cloudflare-go/v7 "
3636 cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
3737 networkingv1 "k8s.io/api/networking/v1"
3838)
@@ -46,28 +46,40 @@ func NewTestScheme() *runtime.Scheme {
4646 return s
4747}
4848
49- var cloudflareAPI cloudflare.API
49+ var (
50+ cloudflareAPI * cloudflare.Client
51+ cloudflareAPIToken string
52+ )
53+
54+ const (
55+ testAccountName = "account"
56+ testContentAnnotation = "cloudflare-operator.io/content"
57+ testDefaultNamespace = "default"
58+ testDNSRecordHost = "dnstest.containeroo-test.org"
59+ testIPv4Address = "1.1.1.1"
60+ testAlternateIPv4Address = "2.2.2.2"
61+ testRecordTypeTXT = "TXT"
62+ testSecretName = "secret"
63+ testWildcardDNSRecordName = "wildcard-containeroo-test-org"
64+ testWildcardHost = "*.containeroo-test.org"
65+ )
5066
5167func initTestCloudflareAPI (t * testing.T ) {
5268 t .Helper ()
5369
54- if cloudflareAPI . APIToken == os . Getenv ( "CF_API_TOKEN" ) && cloudflareAPI . APIToken != "" {
70+ if cloudflareAPI != nil && cloudflareAPIToken == os . Getenv ( "CF_API_TOKEN" ) {
5571 return
5672 }
5773
58- api , err := cloudflare .NewWithAPIToken (os .Getenv ("CF_API_TOKEN" ))
59- if err != nil {
60- t .Fatalf ("failed to initialize test Cloudflare API: %v" , err )
61- }
62-
63- cloudflareAPI = * api
74+ cloudflareAPIToken = os .Getenv ("CF_API_TOKEN" )
75+ cloudflareAPI = newCloudflareClient (cloudflareAPIToken )
6476}
6577
6678func NewTestAccountObjects () (* corev1.Secret , * cloudflareoperatoriov1.Account ) {
6779 secret := & corev1.Secret {
6880 ObjectMeta : metav1.ObjectMeta {
69- Name : "secret" ,
70- Namespace : "default" ,
81+ Name : testSecretName ,
82+ Namespace : testDefaultNamespace ,
7183 },
7284 Data : map [string ][]byte {
7385 "apiToken" : []byte (os .Getenv ("CF_API_TOKEN" )),
@@ -76,7 +88,7 @@ func NewTestAccountObjects() (*corev1.Secret, *cloudflareoperatoriov1.Account) {
7688
7789 account := & cloudflareoperatoriov1.Account {
7890 ObjectMeta : metav1.ObjectMeta {
79- Name : "account" ,
91+ Name : testAccountName ,
8092 },
8193 Spec : cloudflareoperatoriov1.AccountSpec {
8294 ApiToken : cloudflareoperatoriov1.AccountSpecApiToken {
@@ -118,13 +130,13 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
118130
119131 account := & cloudflareoperatoriov1.Account {
120132 ObjectMeta : metav1.ObjectMeta {
121- Name : "account" ,
133+ Name : testAccountName ,
122134 },
123135 Spec : cloudflareoperatoriov1.AccountSpec {
124136 ApiToken : cloudflareoperatoriov1.AccountSpecApiToken {
125137 SecretRef : corev1.SecretReference {
126- Name : "secret" ,
127- Namespace : "default" ,
138+ Name : testSecretName ,
139+ Namespace : testDefaultNamespace ,
128140 },
129141 },
130142 },
@@ -150,8 +162,8 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
150162
151163 secret := & corev1.Secret {
152164 ObjectMeta : metav1.ObjectMeta {
153- Name : "secret" ,
154- Namespace : "default" ,
165+ Name : testSecretName ,
166+ Namespace : testDefaultNamespace ,
155167 },
156168 Data : map [string ][]byte {
157169 "invalid" : []byte ("invalid" ),
@@ -160,13 +172,13 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
160172
161173 account := & cloudflareoperatoriov1.Account {
162174 ObjectMeta : metav1.ObjectMeta {
163- Name : "account" ,
175+ Name : testAccountName ,
164176 },
165177 Spec : cloudflareoperatoriov1.AccountSpec {
166178 ApiToken : cloudflareoperatoriov1.AccountSpecApiToken {
167179 SecretRef : corev1.SecretReference {
168- Name : "secret" ,
169- Namespace : "default" ,
180+ Name : testSecretName ,
181+ Namespace : testDefaultNamespace ,
170182 },
171183 },
172184 },
@@ -229,6 +241,6 @@ func TestCloudflareAPIForAccountName(t *testing.T) {
229241
230242 api , err := cloudflareAPIForAccountName (context .TODO (), kubeClient , otherAccount .Name )
231243 g .Expect (err ).ToNot (HaveOccurred ())
232- g .Expect (api . APIToken ). To ( Equal ( string ( otherSecret . Data [ "apiToken" ]) ))
244+ g .Expect (api ). ToNot ( BeNil ( ))
233245 })
234246}
0 commit comments