Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenairn committed Nov 16, 2023
1 parent f290711 commit ec17e76
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
40 changes: 13 additions & 27 deletions test/e2e/gateway_single_spoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe("Gateway single target cluster", func() {
Expect(err).ToNot(HaveOccurred())

By("creating a Gateway in the hub")
hostname = gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, "."))
hostname = gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, "."))
gw = NewGatewayBuilder(testID, GatewayClassName, tconfig.HubNamespace()).WithListener(gatewayapi.Listener{
Name: "https",
Hostname: &hostname,
Expand Down Expand Up @@ -238,42 +238,28 @@ var _ = Describe("Gateway single target cluster", func() {
var dnsPolicy *mgcv1alpha1.DNSPolicy

BeforeEach(func(ctx SpecContext) {

By("creating a DNSPolicy in the hub")

dnsPolicy = &mgcv1alpha1.DNSPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: testID,
Namespace: tconfig.HubNamespace(),
},
Spec: mgcv1alpha1.DNSPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Kind: "Gateway",
Name: gatewayapi.ObjectName(testID),
Namespace: Pointer(gatewayapi.Namespace(tconfig.HubNamespace())),
},
RoutingStrategy: v1alpha1.LoadBalancedRoutingStrategy,
},
}
err := tconfig.HubClient().Create(ctx, dnsPolicy)
Expect(err).ToNot(HaveOccurred())
dnsPolicy := NewDNSPolicyBuilder(testID, tconfig.HubNamespace()).
WithProviderManagedZone(managedZone.Name).
WithTargetGateway(testID).WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy).
DNSPolicy
Expect(tconfig.HubClient().Create(ctx, dnsPolicy)).To(Succeed())
})

AfterEach(func(ctx SpecContext) {
err := tconfig.HubClient().Delete(ctx, dnsPolicy)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: strings.Join([]string{testID, tconfig.ManagedZone()}, "."),
Name: strings.Join([]string{testID, managedZone.Spec.DomainName}, "."),
Namespace: tconfig.HubNamespace(),
},
}
err = tconfig.HubClient().Delete(ctx, secret)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
cert := &certmanv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: strings.Join([]string{testID, tconfig.ManagedZone()}, "."),
Name: strings.Join([]string{testID, managedZone.Spec.DomainName}, "."),
Namespace: tconfig.HubNamespace(),
},
}
Expand Down Expand Up @@ -311,7 +297,7 @@ var _ = Describe("Gateway single target cluster", func() {
By("ensuring the authoritative nameserver resolves the hostname")

// speed up things by using the authoritative nameserver
nameservers, err := net.LookupNS(tconfig.ManagedZone())
nameservers, err := net.LookupNS(managedZone.Spec.DomainName)
Expect(err).ToNot(HaveOccurred())
GinkgoWriter.Printf("[debug] authoritative nameserver used for DNS record resolution: %s\n", nameservers[0].Host)

Expand Down Expand Up @@ -362,8 +348,8 @@ var _ = Describe("Gateway single target cluster", func() {
if gw.Spec.Listeners == nil {
gw.Spec.Listeners = []gatewayapi.Listener{}
}
wildcardHostname = gatewayapi.Hostname(strings.Join([]string{"*", tconfig.ManagedZone()}, "."))
secretName := gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, "."))
wildcardHostname = gatewayapi.Hostname(strings.Join([]string{"*", managedZone.Spec.DomainName}, "."))
secretName := gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, "."))
AddListener("wildcard", wildcardHostname, gatewayapi.ObjectName(secretName), gw)
err = tconfig.HubClient().Update(ctx, gw)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -422,7 +408,7 @@ var _ = Describe("Gateway single target cluster", func() {
if gw.Spec.Listeners == nil {
gw.Spec.Listeners = []gatewayapi.Listener{}
}
otherHostname = gatewayapi.Hostname(strings.Join([]string{"other", tconfig.ManagedZone()}, "."))
otherHostname = gatewayapi.Hostname(strings.Join([]string{"other", managedZone.Spec.DomainName}, "."))
AddListener("other", otherHostname, gatewayapi.ObjectName(otherHostname), gw)
Eventually(func(g Gomega, ctx SpecContext) {
err = tconfig.HubClient().Update(ctx, gw)
Expand Down Expand Up @@ -471,7 +457,7 @@ var _ = Describe("Gateway single target cluster", func() {
err := tconfig.HubClient().Delete(ctx, tlsPolicy,
client.PropagationPolicy(metav1.DeletePropagationForeground))
Expect(err).ToNot(HaveOccurred())
hostname = gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, "."))
hostname = gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, "."))
Eventually(func(g Gomega, ctx SpecContext) {
secret := &corev1.Secret{}
err = tconfig.HubClient().Get(ctx, client.ObjectKey{Name: string(hostname), Namespace: tconfig.HubNamespace()}, secret)
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1"
. "github.com/Kuadrant/multicluster-gateway-controller/test/util"
)

var tconfig SuiteConfig
var (
tconfig SuiteConfig
managedZone *v1alpha1.ManagedZone
)

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -31,6 +36,7 @@ var _ = BeforeSuite(func(ctx SpecContext) {
err = tconfig.InstallPrerequisites(ctx)
Expect(err).NotTo(HaveOccurred())

Expect(tconfig.HubClient().Get(ctx, client.ObjectKey{Namespace: tconfig.HubNamespace(), Name: tconfig.ManagedZoneName()}, managedZone)).To(Succeed())
})

var _ = AfterSuite(func(ctx SpecContext) {
Expand Down
18 changes: 9 additions & 9 deletions test/util/suite_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
ClusterSetLabelValue = "true"

// configuration environment variables
managedZoneEnvvar = "TEST_MANAGED_ZONE"
managedZoneNameEnvvar = "TEST_MANAGED_ZONE_NAME"
hubNamespaceEnvvar = "TEST_HUB_NAMESPACE"
hubKubeContextEnvvar = "TEST_HUB_KUBE_CONTEXT"
spokeKubeContextPrefixEnvvar = "TEST_SPOKE_KUBE_CONTEXT_PREFIX"
Expand All @@ -44,11 +44,11 @@ const (
)

type SuiteConfig struct {
cpClient client.Client
dpClients []client.Client
hubNamespace string
managedZone string
cleanupList []client.Object
cpClient client.Client
dpClients []client.Client
hubNamespace string
managedZoneName string
cleanupList []client.Object
}

func (cfg *SuiteConfig) Build() error {
Expand All @@ -57,8 +57,8 @@ func (cfg *SuiteConfig) Build() error {
if cfg.hubNamespace = os.Getenv(hubNamespaceEnvvar); cfg.hubNamespace == "" {
return fmt.Errorf("env variable '%s' must be set", hubNamespaceEnvvar)
}
if cfg.managedZone = os.Getenv(managedZoneEnvvar); cfg.managedZone == "" {
return fmt.Errorf("env variable '%s' must be set", managedZoneEnvvar)
if cfg.managedZoneName = os.Getenv(managedZoneNameEnvvar); cfg.managedZoneName == "" {
return fmt.Errorf("env variable '%s' must be set", managedZoneNameEnvvar)
}

var hubKubeContext string
Expand Down Expand Up @@ -153,7 +153,7 @@ func (cfg *SuiteConfig) GenerateName() string {
return namegenerator.NewNameGenerator(nBig.Int64()).Generate()
}

func (cfg *SuiteConfig) ManagedZone() string { return cfg.managedZone }
func (cfg *SuiteConfig) ManagedZoneName() string { return cfg.managedZoneName }

func (cfg *SuiteConfig) HubNamespace() string { return cfg.hubNamespace }

Expand Down

0 comments on commit ec17e76

Please sign in to comment.