Skip to content

Commit

Permalink
Fix proxy_address_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ammujumdar-bcom committed Nov 6, 2024
1 parent 15300b2 commit 6378df7
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/providers"
"github.com/vmware-tanzu/vm-operator/pkg/record"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
)

const (
Expand Down Expand Up @@ -184,7 +184,7 @@ func (r *Reconciler) ReconcileNormal(ctx *pkgctx.WebConsoleRequestContext) error
ctx.WebConsoleRequest.Status.Response = ticket
ctx.WebConsoleRequest.Status.ExpiryTime = metav1.NewTime(metav1.Now().Add(DefaultExpiryTime))

proxyAddr, err := util.ProxyAddress(ctx, r)
proxyAddr, err := webconsole_util.ProxyAddress(ctx, r)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
webconsolerequest "github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

Expand Down Expand Up @@ -83,8 +83,8 @@ func intgTestsReconcile() {

proxySvc = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: util.ProxyAddrServiceName,
Namespace: util.ProxyAddrServiceNamespace,
Name: webconsole_util.ProxyAddrServiceName,
Namespace: webconsole_util.ProxyAddrServiceNamespace,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/providers/fake"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

Expand Down Expand Up @@ -72,8 +72,8 @@ func unitTestsReconcile() {

proxySvc = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: util.ProxyAddrServiceName,
Namespace: util.ProxyAddrServiceNamespace,
Name: webconsole_util.ProxyAddrServiceName,
Namespace: webconsole_util.ProxyAddrServiceNamespace,
},
Status: corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/vmware-tanzu/vm-operator/pkg/patch"
"github.com/vmware-tanzu/vm-operator/pkg/providers"
"github.com/vmware-tanzu/vm-operator/pkg/record"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
)

const (
Expand Down Expand Up @@ -176,7 +176,7 @@ func (r *Reconciler) ReconcileNormal(ctx *pkgctx.WebConsoleRequestContextV1) err
ctx.WebConsoleRequest.Status.Response = ticket
ctx.WebConsoleRequest.Status.ExpiryTime = metav1.NewTime(metav1.Now().Add(DefaultExpiryTime))

proxyAddr, err := util.ProxyAddress(ctx, r)
proxyAddr, err := webconsole_util.ProxyAddress(ctx, r)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
webconsolerequest "github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

Expand Down Expand Up @@ -81,8 +81,8 @@ func intgTestsReconcile() {

proxySvc = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: util.ProxyAddrServiceName,
Namespace: util.ProxyAddrServiceNamespace,
Name: webconsole_util.ProxyAddrServiceName,
Namespace: webconsole_util.ProxyAddrServiceNamespace,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/providers/fake"
"github.com/vmware-tanzu/vm-operator/pkg/util"
webconsole_util "github.com/vmware-tanzu/vm-operator/pkg/util/webconsole"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

Expand Down Expand Up @@ -67,8 +67,8 @@ func unitTestsReconcile() {

proxySvc = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: util.ProxyAddrServiceName,
Namespace: util.ProxyAddrServiceNamespace,
Name: webconsole_util.ProxyAddrServiceName,
Namespace: webconsole_util.ProxyAddrServiceNamespace,
},
Status: corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ require (
github.com/vmware-tanzu/net-operator-api v0.0.0-20240523152550-862e2c4eb0e0
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240902045731-00a14868c72d
github.com/vmware-tanzu/vm-operator/api v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/capabilities v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/appplatform v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/capabilities v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/storage-policy-quota v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/tanzu-topology v0.0.0-00010101000000-000000000000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package util
package webconsole

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package util
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package webconsole

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"
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"

appv1a1 "github.com/vmware-tanzu/vm-operator/external/appplatform/api/v1alpha1"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

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

const (
Expand Down Expand Up @@ -49,10 +54,12 @@ var _ = Describe("Test Proxy Address", func() {
api = nil
initialObjects = nil
ctx = pkgcfg.NewContext()
withFuncs = interceptor.Funcs{}
})

JustBeforeEach(func() {
k8sClient = fake.NewClientBuilder().WithObjects(initialObjects...).Build()
client = builder.NewFakeClientWithInterceptors(
withFuncs, initialObjects...)
})

When("Simplified Enablement FSS is disabled", func() {
Expand All @@ -74,7 +81,7 @@ var _ = Describe("Test Proxy Address", func() {
})

It("Should always return the virtual IP", func() {
str, err := ProxyAddress(ctx, k8sClient)
str, err := ProxyAddress(ctx, client)
Expect(err).To(BeNil())
Expect(str).To(Equal(virtualIP))
})
Expand All @@ -89,7 +96,7 @@ var _ = Describe("Test Proxy Address", func() {
Namespace: "vmware-system-supervisor-services",
},
Spec: appv1a1.SupervisorPropertiesSpec{
APIServerDNSNames: []string{apiServerDNSName},
APIServerDNSNames: []string{},
},
}
ctx = pkgcfg.UpdateContext(ctx, func(config *pkgcfg.Config) {
Expand All @@ -100,7 +107,7 @@ var _ = Describe("Test Proxy Address", func() {
})

It("Should always return the virtual IP", func() {
str, err := ProxyAddress(ctx, k8sClient)
str, err := ProxyAddress(ctx, client)
Expect(err).To(BeNil())
Expect(str).To(Equal(virtualIP))
})
Expand All @@ -126,7 +133,7 @@ var _ = Describe("Test Proxy Address", func() {
})

It("Should always return the DNS Name", func() {
str, err := ProxyAddress(ctx, k8sClient)
str, err := ProxyAddress(ctx, client)
Expect(err).To(BeNil())
Expect(str).To(Equal(apiServerDNSName))
})
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/webconsole/webconsole_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package webconsole

import (
"testing"

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

func TestImage(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Web Console Suite Test")
}

0 comments on commit 6378df7

Please sign in to comment.