Skip to content

Commit

Permalink
add unit tests for pkg/configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Ilario <[email protected]>
  • Loading branch information
filariow committed Jul 12, 2024
1 parent 52156fe commit 28896b4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit 28896b4

Please sign in to comment.