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

Commit

Permalink
GH-496 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymvavilov committed Nov 2, 2023
1 parent dd9d921 commit 34d03f0
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 163 deletions.
2 changes: 1 addition & 1 deletion pkg/dns/fake/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (h *FakeHostService) CleanupDNSRecords(_ context.Context, _ traffic.Interfa

func (h *FakeHostService) CreateDNSRecord(_ context.Context, subDomain string, _ *v1alpha1.ManagedZone, _ metav1.Object) (*v1alpha1.DNSRecord, error) {
if subDomain == Cluster {
return nil, fmt.Errorf(FailCreateDNSSubdomain)
return nil, fmt.Errorf("failcreate")
}
record := v1alpha1.DNSRecord{}
return &record, nil
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/gateway_single_spoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("Gateway single target cluster", func() {

By("creating a Gateway in the hub")
hostname = gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, "."))
gw = NewTestGateway(testID, gateway.MultiClusterGatewayClass, tconfig.HubNamespace()).WithListener(gatewayapi.Listener{
gw = NewTestGateway(testID, gateway.MultiClusterGatewayClass, tconfig.HubNamespace(), "", "").WithListener(gatewayapi.Listener{
Name: "https",
Hostname: &hostname,
Port: 443,
Expand Down
57 changes: 33 additions & 24 deletions test/gateway_integration/placement_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ package gateway_integration

import (
"context"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1"
"github.com/go-logr/logr"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"time"

"github.com/google/uuid"
Expand All @@ -22,26 +26,31 @@ import (
)

const (
TestTimeoutMedium = time.Second * 10
TestTimeoutLong = time.Second * 30
ConsistentlyTimeoutMedium = time.Second * 60
TestRetryIntervalMedium = time.Millisecond * 250
TestPlacedGatewayName = "test-placed-gateway"
TestPlacedClusterControlName = "test-placed-control"
TestPlaceClusterWorkloadName = "test-placed-workload-1"
TestAttachedRouteName = "test.example.com"
OtherAttachedRouteName = "other.example.com"
TestWildCardListenerName = "wildcard"
TestWildCardListenerHost = "*.example.com"
TestAttachedRouteAddressOne = "172.0.0.1"
TestAttachedRouteAddressTwo = "172.0.0.2"
nsSpoke1Name = "test-spoke-cluster-1"
nsSpoke2Name = "test-spoke-cluster-2"
defaultNS = "default"
gatewayFinalizer = "kuadrant.io/gateway"
providerCredential = "secretname"
TestTimeoutMedium = time.Second * 10
TestTimeoutLong = time.Second * 30
ConsistentlyTimeoutMedium = time.Second * 60
TestRetryIntervalMedium = time.Millisecond * 250
nsSpoke1Name = "test-spoke-cluster-1"
nsSpoke2Name = "test-spoke-cluster-2"
defaultNS = "default"
gatewayFinalizer = "kuadrant.io/gateway"
providerCredential = "secretname"
)

var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
ctx context.Context
cancel context.CancelFunc
logger logr.Logger
providerFactory = func(ctx context.Context, managedZone *v1alpha1.ManagedZone) (dns.Provider, error) {
return &dns.FakeProvider{}, nil
}
)

func testClient() client.Client { return k8sClient }

// FakeOCMPlacer has one gateway called "test-placed-gateway"
// placed on two clusters called
// "test-placed-control" with address value of "172.0.0.3" and
Expand All @@ -64,20 +73,20 @@ func NewFakeOCMPlacer(placedGatewayName, attachedRouteName string) *FakeOCMPlace
placedGatewayName: placedGatewayName,
placedClusters: []placedClusters{
{
name: TestPlacedClusterControlName,
attachedRouteAddress: TestAttachedRouteAddressOne,
name: testutil.TestPlacedClusterControlName,
attachedRouteAddress: testutil.TestAttachedRouteAddressOne,
},
{
name: TestPlaceClusterWorkloadName,
attachedRouteAddress: TestAttachedRouteAddressTwo,
name: testutil.TestPlaceClusterWorkloadName,
attachedRouteAddress: testutil.TestAttachedRouteAddressTwo,
},
},
attachedRouteName: attachedRouteName,
}
}

func NewTestOCMPlacer() *FakeOCMPlacer {
return NewFakeOCMPlacer(TestPlacedGatewayName, TestAttachedRouteName)
return NewFakeOCMPlacer(testutil.TestPlacedGatewayName, testutil.TestAttachedRouteName)
}

func (f FakeOCMPlacer) Place(ctx context.Context, upstream *gatewayv1beta1.Gateway, downstream *gatewayv1beta1.Gateway, children ...metav1.Object) (sets.Set[string], error) {
Expand All @@ -101,7 +110,7 @@ func (f FakeOCMPlacer) GetClusters(ctx context.Context, gateway *gatewayv1beta1.
func (f FakeOCMPlacer) ListenerTotalAttachedRoutes(ctx context.Context, gateway *gatewayv1beta1.Gateway, listenerName string, downstream string) (int, error) {
count := 0
for _, placedCluster := range f.placedClusters {
if gateway.Name == f.placedGatewayName && (listenerName == f.attachedRouteName || listenerName == TestWildCardListenerName) && downstream == placedCluster.name {
if gateway.Name == f.placedGatewayName && (listenerName == f.attachedRouteName || listenerName == testutil.TestWildCardListenerName) && downstream == placedCluster.name {
count = 1
}
}
Expand Down
17 changes: 0 additions & 17 deletions test/gateway_integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import (
"path/filepath"
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
ocmclusterv1 "open-cluster-management.io/api/cluster/v1"
ocmclusterv1beta1 "open-cluster-management.io/api/cluster/v1beta1"
ocmworkv1 "open-cluster-management.io/api/work/v1"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand All @@ -38,28 +36,13 @@ import (

"github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1"
. "github.com/Kuadrant/multicluster-gateway-controller/pkg/controllers/gateway"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/dns"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/placement"
//+kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
ctx context.Context
cancel context.CancelFunc
logger logr.Logger
providerFactory = func(ctx context.Context, managedZone *v1alpha1.ManagedZone) (dns.Provider, error) {
return &dns.FakeProvider{}, nil
}
)

func testClient() client.Client { return k8sClient }

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

Expand Down
Loading

0 comments on commit 34d03f0

Please sign in to comment.