From 28896b47ce9f1aa53677ebab46af30cab7c02525 Mon Sep 17 00:00:00 2001 From: Francesco Ilario Date: Fri, 12 Jul 2024 17:18:24 +0200 Subject: [PATCH] add unit tests for pkg/configuration Signed-off-by: Francesco Ilario --- pkg/configuration/configuration_test.go | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/configuration/configuration_test.go b/pkg/configuration/configuration_test.go index 226e0004..72a86af8 100644 --- a/pkg/configuration/configuration_test.go +++ b/pkg/configuration/configuration_test.go @@ -3,6 +3,7 @@ package configuration_test import ( "testing" + "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/registration-service/pkg/configuration" "github.com/codeready-toolchain/registration-service/test" commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration" @@ -68,6 +69,7 @@ func TestRegistrationService(t *testing.T) { assert.InDelta(t, float32(0), regServiceCfg.Verification().CaptchaRequiredScore(), 0.01) assert.True(t, regServiceCfg.Verification().CaptchaAllowLowScoreReactivation()) assert.Empty(t, regServiceCfg.Verification().CaptchaServiceAccountFileContents()) + assert.False(t, regServiceCfg.PublicViewerEnabled()) }) t.Run("non-default", func(t *testing.T) { // given @@ -151,5 +153,42 @@ func TestRegistrationService(t *testing.T) { assert.InDelta(t, float32(0.5), regServiceCfg.Verification().CaptchaRequiredScore(), 0.01) assert.False(t, regServiceCfg.Verification().CaptchaAllowLowScoreReactivation()) assert.Equal(t, "example-content", regServiceCfg.Verification().CaptchaServiceAccountFileContents()) + assert.False(t, regServiceCfg.PublicViewerEnabled()) }) } + +func TestPublicViewer(t *testing.T) { + tt := []struct { + expectedValue bool + publicViewerConfig *v1alpha1.PublicViewerConfiguration + }{ + { + expectedValue: true, + publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: true}, + }, + { + expectedValue: false, + publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: false}, + }, + { + expectedValue: false, + publicViewerConfig: nil, + }, + } + + for _, tc := range tt { + + t.Run("public-viewer is enabled", func(t *testing.T) { + // given + cfg := commonconfig.NewToolchainConfigObjWithReset(t) + cfg.Spec.Host.PublicViewerConfig = tc.publicViewerConfig + secrets := make(map[string]map[string]string) + regServiceCfg := configuration.NewRegistrationServiceConfig(cfg, secrets) + + // then + + // when + assert.Equal(t, tc.expectedValue, regServiceCfg.PublicViewerEnabled()) + }) + } +}