feat: add channel test env toggle
This commit is contained in:
@@ -31,5 +31,11 @@ func GetMonitorSetting() *MonitorSetting {
|
||||
monitorSetting.AutoTestChannelMinutes = float64(frequency)
|
||||
}
|
||||
}
|
||||
if enabled, ok := os.LookupEnv("CHANNEL_TEST_ENABLED"); ok {
|
||||
parsed, err := strconv.ParseBool(enabled)
|
||||
if err == nil {
|
||||
monitorSetting.AutoTestChannelEnabled = parsed
|
||||
}
|
||||
}
|
||||
return &monitorSetting
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package operation_setting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetMonitorSetting_ChannelTestEnabledEnvOverridesEnabledConfig(t *testing.T) {
|
||||
orig := monitorSetting
|
||||
t.Cleanup(func() { monitorSetting = orig })
|
||||
|
||||
t.Setenv("CHANNEL_TEST_ENABLED", "false")
|
||||
t.Setenv("CHANNEL_TEST_FREQUENCY", "5")
|
||||
monitorSetting = MonitorSetting{
|
||||
AutoTestChannelEnabled: true,
|
||||
AutoTestChannelMinutes: 20,
|
||||
}
|
||||
|
||||
setting := GetMonitorSetting()
|
||||
|
||||
require.NotNil(t, setting)
|
||||
assert.False(t, setting.AutoTestChannelEnabled)
|
||||
assert.Equal(t, float64(5), setting.AutoTestChannelMinutes)
|
||||
}
|
||||
|
||||
func TestGetMonitorSetting_ChannelTestEnabledEnvCanEnableDisabledConfig(t *testing.T) {
|
||||
orig := monitorSetting
|
||||
t.Cleanup(func() { monitorSetting = orig })
|
||||
|
||||
t.Setenv("CHANNEL_TEST_ENABLED", "true")
|
||||
monitorSetting = MonitorSetting{
|
||||
AutoTestChannelEnabled: false,
|
||||
AutoTestChannelMinutes: 12,
|
||||
}
|
||||
|
||||
setting := GetMonitorSetting()
|
||||
|
||||
require.NotNil(t, setting)
|
||||
assert.True(t, setting.AutoTestChannelEnabled)
|
||||
assert.Equal(t, float64(12), setting.AutoTestChannelMinutes)
|
||||
}
|
||||
Reference in New Issue
Block a user