mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 06:02:58 +02:00
* add --track-logs-interval flag Signed-off-by: pznamensky <kompastver@gmail.com> * address review nits: logsInterval plumbing and test coverage - kubedog: move defaultLogsInterval next to TrackOptions in options.go, where the field it defaults lives - kubedog: pass logsInterval through newProgressPrinter instead of a post-construction field assignment; zero falls back to the default - kubedog: cover WithLogsInterval and the LogsInterval default in tracker tests - config: document that defaultTrackLogsInterval is shared by sync and apply and mirrors kubedog's default - config: add a negative-interval validation test case Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: pznamensky <kompastver@gmail.com> Signed-off-by: yxxhero <aiopsclub@163.com> Co-authored-by: yxxhero <aiopsclub@163.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTrackLogsIntervalDefault(t *testing.T) {
|
|
require.Equal(t, 10*time.Second, NewApplyOptions().TrackLogsInterval)
|
|
require.Equal(t, 10*time.Second, NewSyncOptions().TrackLogsInterval)
|
|
}
|
|
|
|
func TestTrackLogsIntervalValidation(t *testing.T) {
|
|
commands := []struct {
|
|
name string
|
|
validate func(time.Duration) error
|
|
}{
|
|
{
|
|
name: "apply",
|
|
validate: func(interval time.Duration) error {
|
|
options := NewApplyOptions()
|
|
options.TrackLogsInterval = interval
|
|
return NewApplyImpl(NewGlobalImpl(&GlobalOptions{}), options).ValidateConfig()
|
|
},
|
|
},
|
|
{
|
|
name: "sync",
|
|
validate: func(interval time.Duration) error {
|
|
options := NewSyncOptions()
|
|
options.TrackLogsInterval = interval
|
|
return NewSyncImpl(NewGlobalImpl(&GlobalOptions{}), options).ValidateConfig()
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, command := range commands {
|
|
t.Run(command.name, func(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
interval time.Duration
|
|
wantErr bool
|
|
}{
|
|
{name: "zero", interval: 0, wantErr: true},
|
|
{name: "negative", interval: -time.Second, wantErr: true},
|
|
{name: "below minimum", interval: 500 * time.Millisecond, wantErr: true},
|
|
{name: "minimum", interval: time.Second},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := command.validate(tt.interval)
|
|
if tt.wantErr {
|
|
require.ErrorContains(t, err, "--track-logs-interval must be at least 1s")
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|