Skip to content

Commit 9e22cc6

Browse files
authored
test(e2e): add integrations e2e tests (#77)
Signed-off-by: BoxBoxJason <contact@boxboxjason.dev>
1 parent d5c4ae3 commit 9e22cc6

15 files changed

Lines changed: 332 additions & 56 deletions

internal/clients/common/kubernetes_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/runtime"
29+
"k8s.io/utils/ptr"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
3132
)
@@ -137,7 +138,7 @@ func TestGetTokenValueFromSecret(t *testing.T) {
137138
Key: "token",
138139
},
139140
},
140-
want: strPtr("my-token-value"),
141+
want: ptr.To("my-token-value"),
141142
wantErr: false,
142143
},
143144
}
@@ -231,7 +232,7 @@ func TestGetTokenValueFromLocalSecret(t *testing.T) {
231232
Key: "token",
232233
},
233234
},
234-
want: strPtr("local-token-value"),
235+
want: ptr.To("local-token-value"),
235236
wantErr: false,
236237
},
237238
"SecretNotFoundReturnsError": {
@@ -294,11 +295,6 @@ func TestGetTokenValueFromLocalSecret(t *testing.T) {
294295
}
295296
}
296297

297-
// strPtr returns a pointer to the given string.
298-
func strPtr(s string) *string {
299-
return &s
300-
}
301-
302298
// containsString checks if a string contains a substring.
303299
func containsString(s, substr string) bool {
304300
return len(s) >= len(substr) && (s == substr || len(substr) == 0 ||

internal/test/e2e/iam/group_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package iam_test
2020

2121
import (
@@ -25,6 +25,7 @@ import (
2525
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2626
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/utils/ptr"
2829

2930
iamv1alpha1 "github.com/crossplane/provider-sonarqube/apis/iam/v1alpha1"
3031
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -54,7 +55,7 @@ func TestGroupCRUD(t *testing.T) {
5455
},
5556
ForProvider: iamv1alpha1.GroupParameters{
5657
Name: groupName,
57-
Description: stringPtr("E2E-managed group"),
58+
Description: ptr.To("E2E-managed group"),
5859
Permissions: &wantPerms,
5960
},
6061
},

internal/test/e2e/iam/helpers_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package iam_test
2020

2121
import (
@@ -24,12 +24,6 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/client"
2525
)
2626

27-
// stringPtr returns a pointer to the supplied string.
28-
func stringPtr(s string) *string { return &s }
29-
30-
// boolPtr returns a pointer to the supplied bool.
31-
func boolPtr(b bool) *bool { return &b }
32-
3327
// kubeKey is a terse alias for client.ObjectKeyFromObject.
3428
func kubeKey(obj client.Object) client.ObjectKey {
3529
return client.ObjectKeyFromObject(obj)

internal/test/e2e/iam/permissionstemplate_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package iam_test
2020

2121
import (
@@ -25,6 +25,7 @@ import (
2525
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2626
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/utils/ptr"
2829

2930
iamv1alpha1 "github.com/crossplane/provider-sonarqube/apis/iam/v1alpha1"
3031
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -53,8 +54,8 @@ func TestPermissionsTemplateCRUD(t *testing.T) {
5354
},
5455
ForProvider: iamv1alpha1.PermissionsTemplateParameters{
5556
Name: templateName,
56-
Description: stringPtr("E2E-managed permissions template"),
57-
ProjectKeyPattern: stringPtr(keyPattern),
57+
Description: ptr.To("E2E-managed permissions template"),
58+
ProjectKeyPattern: ptr.To(keyPattern),
5859
},
5960
},
6061
}

internal/test/e2e/iam/user_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package iam_test
2020

2121
import (
@@ -25,9 +25,10 @@ import (
2525

2626
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2727
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
28-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2928
corev1 "k8s.io/api/core/v1"
29+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+
"k8s.io/utils/ptr"
3132

3233
iamv1alpha1 "github.com/crossplane/provider-sonarqube/apis/iam/v1alpha1"
3334
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -73,8 +74,8 @@ func TestUserCRUD(t *testing.T) {
7374
ForProvider: iamv1alpha1.UserParameters{
7475
Login: userLogin,
7576
Name: userName,
76-
Email: stringPtr(userEmail),
77-
Local: boolPtr(true),
77+
Email: ptr.To(userEmail),
78+
Local: ptr.To(true),
7879
PasswordSecretRef: &xpv1.SecretKeySelector{
7980
Key: secretKey,
8081
SecretReference: xpv1.SecretReference{
@@ -84,7 +85,7 @@ func TestUserCRUD(t *testing.T) {
8485
},
8586
// Anonymise on delete so re-creating with the same login
8687
// after a previous run leaves no observable trace.
87-
Anonymize: boolPtr(true),
88+
Anonymize: ptr.To(true),
8889
},
8990
},
9091
}

internal/test/e2e/instance/helpers_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,21 +16,12 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package instance_test
2020

2121
import (
2222
"sigs.k8s.io/controller-runtime/pkg/client"
2323
)
2424

25-
// stringPtr returns a pointer to the supplied string — useful for the
26-
// many optional *string fields in the instance API types.
27-
func stringPtr(s string) *string { return &s }
28-
29-
// boolPtr returns a pointer to the supplied bool.
30-
func boolPtr(b bool) *bool { return &b }
31-
3225
// kubeKey is a terse alias for client.ObjectKeyFromObject to keep the
3326
// polling loops in the individual test files readable.
3427
func kubeKey(obj client.Object) client.ObjectKey {

internal/test/e2e/instance/project_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package instance_test
2020

2121
import (
@@ -25,6 +25,7 @@ import (
2525
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2626
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/utils/ptr"
2829

2930
instancev1alpha1 "github.com/crossplane/provider-sonarqube/apis/instance/v1alpha1"
3031
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -56,14 +57,14 @@ func TestProjectCRUD(t *testing.T) {
5657
ForProvider: instancev1alpha1.ProjectParameters{
5758
Key: projKey,
5859
Name: projName,
59-
Visibility: stringPtr(visPublic),
60-
DefaultBranch: stringPtr("main"),
60+
Visibility: ptr.To(visPublic),
61+
DefaultBranch: ptr.To("main"),
6162
Tags: &[]string{"crossplane", "e2e"},
6263
// Pin to the built-in "Sonar way" gate. Leaving this unset
6364
// causes Crossplane's reference resolver to issue a server
6465
// side apply with qualityGateName="" which fails the field's
6566
// MinLength=1 CRD validation.
66-
QualityGateName: stringPtr("Sonar way"),
67+
QualityGateName: ptr.To("Sonar way"),
6768
},
6869
},
6970
}

internal/test/e2e/instance/qualitygate_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package instance_test
2020

2121
import (
@@ -27,6 +27,7 @@ import (
2727
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2828
corev1 "k8s.io/api/core/v1"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/utils/ptr"
3031

3132
instancev1alpha1 "github.com/crossplane/provider-sonarqube/apis/instance/v1alpha1"
3233
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -56,7 +57,7 @@ func TestQualityGateCRUD(t *testing.T) {
5657
ForProvider: instancev1alpha1.QualityGateParameters{
5758
Name: qgName,
5859
Conditions: []instancev1alpha1.QualityGateConditionParameters{
59-
{Metric: "blocker_violations", Op: stringPtr("GT"), Error: "0"},
60+
{Metric: "blocker_violations", Op: ptr.To("GT"), Error: "0"},
6061
},
6162
},
6263
},
@@ -104,7 +105,7 @@ func TestQualityGateInvalidMetric(t *testing.T) {
104105
ForProvider: instancev1alpha1.QualityGateParameters{
105106
Name: qgName,
106107
Conditions: []instancev1alpha1.QualityGateConditionParameters{
107-
{Metric: "not_a_real_metric", Op: stringPtr("GT"), Error: "0"},
108+
{Metric: "not_a_real_metric", Op: ptr.To("GT"), Error: "0"},
108109
},
109110
},
110111
},

internal/test/e2e/instance/qualityprofile_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package instance_test
2020

2121
import (
@@ -25,6 +25,7 @@ import (
2525
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2626
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/utils/ptr"
2829

2930
instancev1alpha1 "github.com/crossplane/provider-sonarqube/apis/instance/v1alpha1"
3031
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -57,7 +58,7 @@ func TestQualityProfileCRUD(t *testing.T) {
5758
ForProvider: instancev1alpha1.QualityProfileParameters{
5859
Name: qpName,
5960
Language: qpLang,
60-
Default: boolPtr(false),
61+
Default: ptr.To(false),
6162
},
6263
},
6364
}

internal/test/e2e/instance/rule_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
/*
24
Copyright 2026 The Crossplane Authors.
35
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
//go:build e2e
18-
1919
package instance_test
2020

2121
import (
@@ -26,6 +26,7 @@ import (
2626
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
2727
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/utils/ptr"
2930

3031
instancev1alpha1 "github.com/crossplane/provider-sonarqube/apis/instance/v1alpha1"
3132
"github.com/crossplane/provider-sonarqube/internal/test/e2e"
@@ -62,8 +63,8 @@ func TestRuleCRUD(t *testing.T) {
6263
Name: ruleName,
6364
TemplateKey: templateKey,
6465
MarkdownDescription: markdown,
65-
Status: stringPtr("READY"),
66-
Type: stringPtr("CODE_SMELL"),
66+
Status: ptr.To("READY"),
67+
Type: ptr.To("CODE_SMELL"),
6768
},
6869
},
6970
}

0 commit comments

Comments
 (0)