Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: refactor deploy helpers #673

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions test/envtest/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,79 +15,4 @@ const (

// tickTime is a generic tick time for the tests' eventual conditions.
tickTime = 500 * time.Millisecond

// dummyValidCACertPEM is a dummy valid CA certificate PEM to be used in tests.
dummyValidCACertPEM = `-----BEGIN CERTIFICATE-----
MIIDPTCCAiWgAwIBAgIUcNKAk2icWRJGwZ5QDpdSkkeF5kUwDQYJKoZIhvcNAQEL
BQAwLjELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQKDAlLb25nIElu
Yy4wHhcNMjQwOTE5MDkwODEzWhcNMjkwOTE4MDkwODEzWjAuMQswCQYDVQQGEwJV
UzELMAkGA1UECAwCQ0ExEjAQBgNVBAoMCUtvbmcgSW5jLjCCASIwDQYJKoZIhvcN
AQEBBQADggEPADCCAQoCggEBAMvDhLM0vTw0QXmgE+sB6gvKx2PUWzvd2tRZoamH
h4RAxYRjgJsJe6WEeAk0tjWQqwAq0Y2MQioMCC4X+L13kpdtomI+4PKjBozg+iTd
ThyV0oQSVHHWzayUzcSODnGR524H9YxmkXV5ImrXwbEqXwiUESPVtjnf/ZzWS01v
gtbu4x3YW+z8kRoXOTpJHKcEoI90SU9F4yeuQsCtbJHeJZRqPr6Kz84ZuHsZ2MeU
os4j1GdMaH3dSysqFv6o1hJ2+6bsrE/ONiGtBb4+tyhivgf+u+ixQwqIERlEJzhI
z/csoAAnfMBY401j2NNUgPpwx5sTQdCz5aFDmanol5152M8CAwEAAaNTMFEwHQYD
VR0OBBYEFK2qd3oRF37acVvgfDeLakx66ioTMB8GA1UdIwQYMBaAFK2qd3oRF37a
cVvgfDeLakx66ioTMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
AAuul+rAztaueTpPIM63nrS4bSZsIatCgAQ5Pihm0+rZ+13BJk4K2GxkS+T0qkB5
34+F3eVhUB4cC+kVkWZrlEzD9BsJwWjnoJK+848znTg+ufTeaOQWslYNqFKjmy2k
K6NE7E6r+JLdNvafJzeDybSTXI1tCzDRWUdj5m+bgruX07B13KIJKrAweCTD1927
WvvfJYxsg8P7dYD9DPlcuOm22ggAaPPu4P/MsnApiq3kJEI/nSGSsboKyjBO2hcz
VF1CYr6Epfyw/47kwuJLCVHjlTgT4haOChW1S8rZILCLXfb8ukM/g3XVYIeEwzsr
KU74cm8lTFCdxlcXePbMdHc=
-----END CERTIFICATE-----
`
// dummyValidCertPEM is a dummy valid certificate PEM to be used in tests.
dummyValidCertPEM = `-----BEGIN CERTIFICATE-----
MIIDPTCCAiUCFG5IolqRiKPMfzTI8peXlaF6cZODMA0GCSqGSIb3DQEBCwUAMFsx
CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5
MRIwEAYDVQQKDAlLb25nIEluYy4xFDASBgNVBAMMC2tvbmdocS50ZWNoMB4XDTI0
MDkyNTA3MjIzOFoXDTM0MDkyMzA3MjIzOFowWzELMAkGA1UEBhMCVVMxCzAJBgNV
BAgMAkNBMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxEjAQBgNVBAoMCUtvbmcgSW5j
LjEUMBIGA1UEAwwLa29uZ2hxLnRlY2gwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQDXmNBzpWyJ0YUdfCamZpJiwRQMn5vVY8iKQrd3dD03DWyPHu/fXlrL
+QPTRip5d1SrxjzQ4S3fgme442BTlElF9d1w1rhg+DIg6NsW1jd+3IZaICnq7BZH
rJGlW+IWJSKHmNQ39nfVQwgL/QdylrYpbB7uwdEDMa78GfXteiXTcuNobCr7VWVz
rY6rQXo/dImWE1PtMp/EZEMsEbgbQpK5+fUnKTmFncVlDAZ2Q3s2MPikV5UhMVyQ
dKQydU0Ev0LRtpsjW8pQdshMG1ilMq6Yg6YU95gakLVjRXMoDlIJOu08mdped+2Y
VIUSXhRyRt1hbkFP0fXG0THfZ3DjH7jRAgMBAAEwDQYJKoZIhvcNAQELBQADggEB
ANEXlNaQKLrB+jsnNjybsTRkvRRmwjnXaQV0jHzjseGsTJoKY5ABBsSRDiHtqB+9
LPTpHhLYJWsHSLwawIJ3aWDDpF4MNTRsvO12v7wM8Q42OSgkP23O6a5ESkyHRBAb
dLVEp+0Z3kjYwPIglIK37PcgDci6Zim73GOfapDEASNbnCu8js2g/ucYPPXkGMxl
PSUER7MTNf9wRbXrroCE+tZw4kUyUh+6taNlU4ialAJLO1x6UGVRHvPgEx0fAAxA
seBH+A9QMvVl2cKcvrOgZ0CWY01aFRO9ROQ7PrYXqRFvOZu8K3QzLw7xYoK1DTp+
kkO/oPy+WIbqEvj7QrhUXpo=
-----END CERTIFICATE-----
`
// dummyValidCertKeyPEM is a dummy valid certificate key PEM to be used in tests.
dummyValidCertKeyPEM = `-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDXmNBzpWyJ0YUd
fCamZpJiwRQMn5vVY8iKQrd3dD03DWyPHu/fXlrL+QPTRip5d1SrxjzQ4S3fgme4
42BTlElF9d1w1rhg+DIg6NsW1jd+3IZaICnq7BZHrJGlW+IWJSKHmNQ39nfVQwgL
/QdylrYpbB7uwdEDMa78GfXteiXTcuNobCr7VWVzrY6rQXo/dImWE1PtMp/EZEMs
EbgbQpK5+fUnKTmFncVlDAZ2Q3s2MPikV5UhMVyQdKQydU0Ev0LRtpsjW8pQdshM
G1ilMq6Yg6YU95gakLVjRX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5kqV8WueY3rgmNOGLnLJasBmE/gt4ihPAoGAG3v93R5tAeSrn7DMHaZt
p+udsNw9mDPYHAzlYtnw1OE/I0ceR5UyCFSzCd00Q8ZYBLf9jRvsO/GUA4F51isE
8/7xyqSxJqDwzv9N8EGkqf/SfMKA3kK3Sc8u+ovhzJu8OxcY+qrpo4+vYWYeW42n
5XBwvWV2ovRMx7Ntw7FUc24=
-----END PRIVATE KEY-----
`
)
23 changes: 12 additions & 11 deletions test/envtest/kongconsumercredential_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/kong/gateway-operator/controller/konnect/ops"
"github.com/kong/gateway-operator/modules/manager"
"github.com/kong/gateway-operator/modules/manager/scheme"
"github.com/kong/gateway-operator/test/helpers/deploy"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
Expand All @@ -40,11 +41,11 @@ func TestKongConsumerCredential_ACL(t *testing.T) {
require.NoError(t, err)
clientNamespaced := client.NewNamespacedClient(mgr.GetClient(), ns.Name)

apiAuth := deployKonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deployKonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)
apiAuth := deploy.KonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deploy.KonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)

consumerID := uuid.NewString()
consumer := deployKongConsumerWithProgrammed(t, ctx, clientNamespaced, &configurationv1.KongConsumer{
consumer := deploy.KongConsumerWithProgrammed(t, ctx, clientNamespaced, &configurationv1.KongConsumer{
Username: "username1",
Spec: configurationv1.KongConsumerSpec{
ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
Expand All @@ -66,15 +67,15 @@ func TestKongConsumerCredential_ACL(t *testing.T) {
require.NoError(t, clientNamespaced.Status().Update(ctx, consumer))

aclGroup := "acl-group1"
KongCredentialACL := deployKongCredentialACL(t, ctx, clientNamespaced, consumer.Name, aclGroup)
kongCredentialACL := deploy.KongCredentialACL(t, ctx, clientNamespaced, consumer.Name, aclGroup)
aclID := uuid.NewString()
tags := []string{
"k8s-generation:1",
"k8s-group:configuration.konghq.com",
"k8s-kind:KongCredentialACL",
"k8s-name:" + KongCredentialACL.Name,
"k8s-name:" + kongCredentialACL.Name,
"k8s-namespace:" + ns.Name,
"k8s-uid:" + string(KongCredentialACL.GetUID()),
"k8s-uid:" + string(kongCredentialACL.GetUID()),
"k8s-version:v1alpha1",
}

Expand Down Expand Up @@ -138,25 +139,25 @@ func TestKongConsumerCredential_ACL(t *testing.T) {
},
nil,
)
require.NoError(t, clientNamespaced.Delete(ctx, KongCredentialACL))
require.NoError(t, clientNamespaced.Delete(ctx, kongCredentialACL))

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsACLSDK.AssertExpectations(t))
}, waitTime, tickTime)

w := setupWatch[configurationv1alpha1.KongCredentialACLList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))

KongCredentialACL = deployKongCredentialACL(t, ctx, clientNamespaced, consumer.Name, aclGroup)
t.Logf("redeployed %s KongCredentialACL resource", client.ObjectKeyFromObject(KongCredentialACL))
kongCredentialACL = deploy.KongCredentialACL(t, ctx, clientNamespaced, consumer.Name, aclGroup)
t.Logf("redeployed %s KongCredentialACL resource", client.ObjectKeyFromObject(kongCredentialACL))
t.Logf("checking if KongConsumer %s removal will delete the associated credentials %s",
client.ObjectKeyFromObject(consumer),
client.ObjectKeyFromObject(KongCredentialACL),
client.ObjectKeyFromObject(kongCredentialACL),
)

require.NoError(t, clientNamespaced.Delete(ctx, consumer))
_ = watchFor(t, ctx, w, watch.Modified,
func(c *configurationv1alpha1.KongCredentialACL) bool {
return c.Name == KongCredentialACL.Name
return c.Name == kongCredentialACL.Name
},
"KongCredentialACL wasn't deleted but it should have been",
)
Expand Down
23 changes: 12 additions & 11 deletions test/envtest/kongconsumercredential_basicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/kong/gateway-operator/controller/konnect/ops"
"github.com/kong/gateway-operator/modules/manager"
"github.com/kong/gateway-operator/modules/manager/scheme"
"github.com/kong/gateway-operator/test/helpers/deploy"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
Expand All @@ -40,11 +41,11 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {
require.NoError(t, err)
clientNamespaced := client.NewNamespacedClient(mgr.GetClient(), ns.Name)

apiAuth := deployKonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deployKonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)
apiAuth := deploy.KonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deploy.KonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)

consumerID := uuid.NewString()
consumer := deployKongConsumerWithProgrammed(t, ctx, clientNamespaced, &configurationv1.KongConsumer{
consumer := deploy.KongConsumerWithProgrammed(t, ctx, clientNamespaced, &configurationv1.KongConsumer{
Username: "username1",
Spec: configurationv1.KongConsumerSpec{
ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
Expand All @@ -67,15 +68,15 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {

password := "password"
username := "username"
KongCredentialBasicAuth := deployKongCredentialBasicAuth(t, ctx, clientNamespaced, consumer.Name, username, password)
kongCredentialBasicAuth := deploy.KongCredentialBasicAuth(t, ctx, clientNamespaced, consumer.Name, username, password)
basicAuthID := uuid.NewString()
tags := []string{
"k8s-generation:1",
"k8s-group:configuration.konghq.com",
"k8s-kind:KongCredentialBasicAuth",
"k8s-name:" + KongCredentialBasicAuth.Name,
"k8s-name:" + kongCredentialBasicAuth.Name,
"k8s-namespace:" + ns.Name,
"k8s-uid:" + string(KongCredentialBasicAuth.GetUID()),
"k8s-uid:" + string(kongCredentialBasicAuth.GetUID()),
"k8s-version:v1alpha1",
}

Expand Down Expand Up @@ -140,25 +141,25 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {
},
nil,
)
require.NoError(t, clientNamespaced.Delete(ctx, KongCredentialBasicAuth))
require.NoError(t, clientNamespaced.Delete(ctx, kongCredentialBasicAuth))

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsBasicAuthSDK.AssertExpectations(t))
}, waitTime, tickTime)

w := setupWatch[configurationv1alpha1.KongCredentialBasicAuthList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))

KongCredentialBasicAuth = deployKongCredentialBasicAuth(t, ctx, clientNamespaced, consumer.Name, username, password)
t.Logf("redeployed %s KongCredentialBasicAuth resource", client.ObjectKeyFromObject(KongCredentialBasicAuth))
kongCredentialBasicAuth = deploy.KongCredentialBasicAuth(t, ctx, clientNamespaced, consumer.Name, username, password)
t.Logf("redeployed %s KongCredentialBasicAuth resource", client.ObjectKeyFromObject(kongCredentialBasicAuth))
t.Logf("checking if KongConsumer %s removal will delete the associated credentials %s",
client.ObjectKeyFromObject(consumer),
client.ObjectKeyFromObject(KongCredentialBasicAuth),
client.ObjectKeyFromObject(kongCredentialBasicAuth),
)

require.NoError(t, clientNamespaced.Delete(ctx, consumer))
_ = watchFor(t, ctx, w, watch.Modified,
func(c *configurationv1alpha1.KongCredentialBasicAuth) bool {
return c.Name == KongCredentialBasicAuth.Name
return c.Name == kongCredentialBasicAuth.Name
},
"KongCredentialBasicAuth wasn't deleted but it should have been",
)
Expand Down
23 changes: 12 additions & 11 deletions test/envtest/kongpluginbinding_managed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/kong/gateway-operator/modules/manager"
"github.com/kong/gateway-operator/modules/manager/scheme"
"github.com/kong/gateway-operator/pkg/consts"
"github.com/kong/gateway-operator/test/helpers/deploy"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
Expand Down Expand Up @@ -50,8 +51,8 @@ func TestKongPluginBindingManaged(t *testing.T) {
require.NoError(t, err)
clientNamespaced := client.NewNamespacedClient(mgr.GetClient(), ns.Name)

apiAuth := deployKonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deployKonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)
apiAuth := deploy.KonnectAPIAuthConfigurationWithProgrammed(t, ctx, clientNamespaced)
cp := deploy.KonnectGatewayControlPlaneWithID(t, ctx, clientNamespaced, apiAuth)

factory := ops.NewMockSDKFactory(t)
sdk := factory.SDK
Expand Down Expand Up @@ -96,8 +97,8 @@ func TestKongPluginBindingManaged(t *testing.T) {
wKongPluginBinding := setupWatch[configurationv1alpha1.KongPluginBindingList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))
wKongPlugin := setupWatch[configurationv1.KongPluginList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))

kongService := deployKongServiceAttachedToCP(t, ctx, clientNamespaced, cp,
WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
kongService := deploy.KongServiceAttachedToCP(t, ctx, clientNamespaced, cp,
deploy.WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
)
t.Cleanup(func() {
require.NoError(t, clientNamespaced.Delete(ctx, kongService))
Expand Down Expand Up @@ -196,13 +197,13 @@ func TestKongPluginBindingManaged(t *testing.T) {

wKongPluginBinding := setupWatch[configurationv1alpha1.KongPluginBindingList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))
wKongPlugin := setupWatch[configurationv1.KongPluginList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))
kongService := deployKongServiceAttachedToCP(t, ctx, clientNamespaced, cp)
kongService := deploy.KongServiceAttachedToCP(t, ctx, clientNamespaced, cp)
t.Cleanup(func() {
require.NoError(t, clientNamespaced.Delete(ctx, kongService))
})
updateKongServiceStatusWithProgrammed(t, ctx, clientNamespaced, kongService, serviceID, cp.GetKonnectStatus().GetKonnectID())
kongRoute := deployKongRouteAttachedToService(t, ctx, clientNamespaced, kongService,
WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
kongRoute := deploy.KongRouteAttachedToService(t, ctx, clientNamespaced, kongService,
deploy.WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
)
t.Cleanup(func() {
require.NoError(t, clientNamespaced.Delete(ctx, kongRoute))
Expand Down Expand Up @@ -300,15 +301,15 @@ func TestKongPluginBindingManaged(t *testing.T) {

wKongPluginBinding := setupWatch[configurationv1alpha1.KongPluginBindingList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))
wKongPlugin := setupWatch[configurationv1.KongPluginList](t, ctx, clientWithWatch, client.InNamespace(ns.Name))
kongService := deployKongServiceAttachedToCP(t, ctx, clientNamespaced, cp,
WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
kongService := deploy.KongServiceAttachedToCP(t, ctx, clientNamespaced, cp,
deploy.WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
)
t.Cleanup(func() {
require.NoError(t, clientNamespaced.Delete(ctx, kongService))
})
updateKongServiceStatusWithProgrammed(t, ctx, clientNamespaced, kongService, serviceID, cp.GetKonnectStatus().GetKonnectID())
kongRoute := deployKongRouteAttachedToService(t, ctx, clientNamespaced, kongService,
WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
kongRoute := deploy.KongRouteAttachedToService(t, ctx, clientNamespaced, kongService,
deploy.WithAnnotation(consts.PluginsAnnotationKey, rateLimitingkongPlugin.Name),
)
t.Cleanup(func() {
require.NoError(t, clientNamespaced.Delete(ctx, kongRoute))
Expand Down
Loading
Loading