diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go index f26f892a7..026adc9e4 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go @@ -146,71 +146,35 @@ func unitTestsReconcile() { Expect(wcrCtx.WebConsoleRequest.Labels).To(HaveKey(webconsolerequest.UUIDLabelKey)) }) - When("SimplifiedEnablement Feature is true", func() { + When("SimplifiedEnablement is enabled", func() { JustBeforeEach(func() { - reconciler = webconsolerequest.NewReconciler( - pkgcfg.UpdateContext( - ctx, - func(config *pkgcfg.Config) { - config.Features.SimplifiedEnablement = true - }, - ), - ctx.Client, - ctx.Logger, - ctx.Recorder, - ctx.VMProvider, + pkgcfg.UpdateContext(ctx, + func(config *pkgcfg.Config) { + config.Features.SimplifiedEnablement = true + }, ) }) - scenarios := []struct { - name string - apiServerDNSName []string - expectedProxy string - }{ - { - name: "API Server DNS Name is set", - apiServerDNSName: []string{"domain-1.test"}, - expectedProxy: "domain-1.test", - }, - { - name: "API Server DNS Name is not set", - apiServerDNSName: []string{}, - expectedProxy: "dummy-proxy-ip", - }, - } + DescribeTable("DNS Names", + func(apiServerDNSName []string, expectedProxy string) { + proxySvcDNS = &appv1a1.SupervisorProperties{ + ObjectMeta: metav1.ObjectMeta{ + Name: "supervisor-env-props", + Namespace: "vmware-system-supervisor-services", + }, + Spec: appv1a1.SupervisorPropertiesSpec{ + APIServerDNSNames: apiServerDNSName, + }, + } + Expect(ctx.Client.Create(ctx, proxySvcDNS)).To(Succeed()) - for _, scenario := range scenarios { - When(scenario.name, func() { - JustBeforeEach(func() { - proxySvcDNS = &appv1a1.SupervisorProperties{ - ObjectMeta: metav1.ObjectMeta{ - Name: util.SupervisorServiceObjName, - Namespace: util.SupervisorServiceObjNamespace, - }, - Spec: appv1a1.SupervisorPropertiesSpec{ - APIServerDNSNames: scenario.apiServerDNSName, - }, - } - initObjects = append(initObjects, proxySvcDNS) - ctx = suite.NewUnitTestContextForController(initObjects...) - reconciler = webconsolerequest.NewReconciler( - ctx, - ctx.Client, - ctx.Logger, - ctx.Recorder, - ctx.VMProvider, - ) - }) - - It("returns success and sets ProxyAddr", func() { - Expect(reconciler.ReconcileNormal(wcrCtx)).To(Succeed()) - - Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal(scenario.expectedProxy)) - }) - }) - } + Expect(reconciler.ReconcileNormal(wcrCtx)).To(Succeed()) + Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal(expectedProxy)) + }, + Entry("API Server DNS Name is set", []string{"domain-1.test"}, "domain-1.test"), + Entry("API Server DNS Name is not set", []string{}, "dummy-proxy-ip"), + ) }) - }) } diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha2/webconsolerequest_unit_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha2/webconsolerequest_unit_test.go index b65de1409..9e701bfc5 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha2/webconsolerequest_unit_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha2/webconsolerequest_unit_test.go @@ -136,69 +136,34 @@ func unitTestsReconcile() { }) }) - When("SimplifiedEnablement Feature is true", func() { + When("SimplifiedEnablement is enabled", func() { JustBeforeEach(func() { - reconciler = webconsolerequest.NewReconciler( - pkgcfg.UpdateContext( - ctx, - func(config *pkgcfg.Config) { - config.Features.SimplifiedEnablement = true - }, - ), - ctx.Client, - ctx.Logger, - ctx.Recorder, - ctx.VMProvider, + pkgcfg.UpdateContext(ctx, + func(config *pkgcfg.Config) { + config.Features.SimplifiedEnablement = true + }, ) }) - scenarios := []struct { - name string - apiServerDNSName []string - expectedProxy string - }{ - { - name: "API Server DNS Name is set", - apiServerDNSName: []string{"domain-1.test"}, - expectedProxy: "domain-1.test", - }, - { - name: "API Server DNS Name is not set", - apiServerDNSName: []string{}, - expectedProxy: "dummy-proxy-ip", + DescribeTable("DNS Names", + func(apiServerDNSName []string, expectedProxy string) { + proxySvcDNS = &appv1a1.SupervisorProperties{ + ObjectMeta: metav1.ObjectMeta{ + Name: "supervisor-env-props", + Namespace: "vmware-system-supervisor-services", + }, + Spec: appv1a1.SupervisorPropertiesSpec{ + APIServerDNSNames: apiServerDNSName, + }, + } + Expect(ctx.Client.Create(ctx, proxySvcDNS)).To(Succeed()) + + Expect(reconciler.ReconcileNormal(wcrCtx)).To(Succeed()) + Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal(expectedProxy)) }, - } - - for _, scenario := range scenarios { - When(scenario.name, func() { - JustBeforeEach(func() { - proxySvcDNS = &appv1a1.SupervisorProperties{ - ObjectMeta: metav1.ObjectMeta{ - Name: util.SupervisorServiceObjName, - Namespace: util.SupervisorServiceObjNamespace, - }, - Spec: appv1a1.SupervisorPropertiesSpec{ - APIServerDNSNames: scenario.apiServerDNSName, - }, - } - initObjects = append(initObjects, proxySvcDNS) - ctx = suite.NewUnitTestContextForController(initObjects...) - reconciler = webconsolerequest.NewReconciler( - ctx, - ctx.Client, - ctx.Logger, - ctx.Recorder, - ctx.VMProvider, - ) - }) - - It("returns success and sets ProxyAddr", func() { - Expect(reconciler.ReconcileNormal(wcrCtx)).To(Succeed()) - - Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal(scenario.expectedProxy)) - }) - }) - } + Entry("API Server DNS Name is set", []string{"domain-1.test"}, "domain-1.test"), + Entry("API Server DNS Name is not set", []string{}, "dummy-proxy-ip"), + ) }) }) }