Skip to content

Commit

Permalink
Add proxy_address_test.go (failing)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammujumdar-bcom committed Nov 6, 2024
1 parent 230d1b3 commit 15300b2
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions pkg/util/proxy_address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package util

import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

appv1a1 "github.com/vmware-tanzu/vm-operator/external/appplatform/api/v1alpha1"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

var _ = Describe("Test Proxy Address", func() {
var (
// err error
ctx context.Context
k8sClient ctrlclient.Client
initialObjects []ctrlclient.Object
proxySvc *corev1.Service
api *appv1a1.SupervisorProperties
)

const (
apiServerDNSName = "domain-1.test"
virtualIP = "dummy-proxy-ip"
)

BeforeEach(func() {
// err = nil
proxySvc = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: ProxyAddrServiceName,
Namespace: ProxyAddrServiceNamespace,
},
Status: corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
IP: virtualIP,
},
},
},
},
}
api = nil
initialObjects = nil
ctx = pkgcfg.NewContext()
})

JustBeforeEach(func() {
k8sClient = fake.NewClientBuilder().WithObjects(initialObjects...).Build()
})

When("Simplified Enablement FSS is disabled", func() {
BeforeEach(func() {
api = &appv1a1.SupervisorProperties{
ObjectMeta: metav1.ObjectMeta{
Name: "supervisor-env-props",
Namespace: "vmware-system-supervisor-services",
},
Spec: appv1a1.SupervisorPropertiesSpec{
APIServerDNSNames: []string{apiServerDNSName},
},
}
ctx = pkgcfg.UpdateContext(ctx, func(config *pkgcfg.Config) {
config.Features.SimplifiedEnablement = false
})

initialObjects = []ctrlclient.Object{proxySvc, api}
})

It("Should always return the virtual IP", func() {
str, err := ProxyAddress(ctx, k8sClient)
Expect(err).To(BeNil())
Expect(str).To(Equal(virtualIP))
})

})

When("API Server DNS Names is NOT set", func() {
BeforeEach(func() {
api = &appv1a1.SupervisorProperties{
ObjectMeta: metav1.ObjectMeta{
Name: "supervisor-env-props",
Namespace: "vmware-system-supervisor-services",
},
Spec: appv1a1.SupervisorPropertiesSpec{
APIServerDNSNames: []string{apiServerDNSName},
},
}
ctx = pkgcfg.UpdateContext(ctx, func(config *pkgcfg.Config) {
config.Features.SimplifiedEnablement = true
})

initialObjects = []ctrlclient.Object{proxySvc, api}
})

It("Should always return the virtual IP", func() {
str, err := ProxyAddress(ctx, k8sClient)
Expect(err).To(BeNil())
Expect(str).To(Equal(virtualIP))
})

})

When("API Server DNS Names is set", func() {
BeforeEach(func() {
api = &appv1a1.SupervisorProperties{
ObjectMeta: metav1.ObjectMeta{
Name: "supervisor-env-props",
Namespace: "vmware-system-supervisor-services",
},
Spec: appv1a1.SupervisorPropertiesSpec{
APIServerDNSNames: []string{apiServerDNSName},
},
}
ctx = pkgcfg.UpdateContext(ctx, func(config *pkgcfg.Config) {
config.Features.SimplifiedEnablement = true
})

initialObjects = []ctrlclient.Object{proxySvc, api}
})

It("Should always return the DNS Name", func() {
str, err := ProxyAddress(ctx, k8sClient)
Expect(err).To(BeNil())
Expect(str).To(Equal(apiServerDNSName))
})

})

})

0 comments on commit 15300b2

Please sign in to comment.