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 e360c1f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 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,45 @@ 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 {
name string
expectedValue bool
publicViewerConfig *v1alpha1.PublicViewerConfiguration
}{
{
name: "public-viewer is explicitly enabled",
expectedValue: true,
publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: true},
},
{
name: "public-viewer is explicitly disabled",
expectedValue: false,
publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: false},
},
{
name: "public-viewer config not set, assume disabled",
expectedValue: false,
publicViewerConfig: nil,
},
}

for _, tc := range tt {
t.Run(tc.name, 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 e360c1f

Please sign in to comment.