Skip to content

Commit

Permalink
Fix MaxTTL config check and missing exit on invalid config root-gg#342
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Antoine Mathieu committed Nov 18, 2020
1 parent cddc0c5 commit dd6f177
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func initConfig() {
config, err = common.LoadConfiguration(configPath)
if err != nil {
fmt.Printf("Unable to load config : %s\n", err)
os.Exit(1)
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (config *Configuration) Initialize() (err error) {
}
}

if config.DefaultTTL > config.MaxTTL {
if config.MaxTTL > 0 && config.DefaultTTL > 0 && config.MaxTTL < config.DefaultTTL {
return fmt.Errorf("DefaultTTL should not be more than MaxTTL")
}

Expand Down
9 changes: 9 additions & 0 deletions server/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ func TestInitializeInvalidDefaultTTL(t *testing.T) {
require.Error(t, err, "able to initialize invalid config")
}

func TestInitializeInfiniteMaxTTL(t *testing.T) {
config := NewConfiguration()
config.DefaultTTL = 10 * 86400
config.MaxTTL = -1

err := config.Initialize()
require.NoError(t, err, "unable to initialize valid config")
}

func TestDisableAutoClean(t *testing.T) {
config := NewConfiguration()
require.True(t, config.IsAutoClean(), "invalid auto clean status")
Expand Down

0 comments on commit dd6f177

Please # to comment.