added testing for auto-pause-interval validation
parent
a5e44b1d54
commit
560d3aa340
|
@ -1250,7 +1250,7 @@ func validateCPUCount(drvName string) {
|
|||
}
|
||||
|
||||
// validateFlags validates the supplied flags against known bad combinations
|
||||
func validateFlags(cmd *cobra.Command, drvName string) {
|
||||
func validateFlags(cmd *cobra.Command, drvName string) { //nolint:gocyclo
|
||||
if cmd.Flags().Changed(humanReadableDiskSize) {
|
||||
err := validateDiskSize(viper.GetString(humanReadableDiskSize))
|
||||
if err != nil {
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -886,3 +887,29 @@ func TestValidateGPUs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAutoPause(t *testing.T) {
|
||||
tests := []struct {
|
||||
interval string
|
||||
shouldError bool
|
||||
}{
|
||||
{"1m0s", false},
|
||||
{"5m", false},
|
||||
{"1s", false},
|
||||
{"0s", true},
|
||||
{"-2m", true},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
input, err := time.ParseDuration(tc.interval)
|
||||
if err != nil {
|
||||
t.Fatalf("test has an invalid input duration of %q", tc.interval)
|
||||
}
|
||||
err = validateAutoPauseInterval(input)
|
||||
if err != nil && !tc.shouldError {
|
||||
t.Errorf("interval of %q failed validation; expected it to pass: %v", input, err)
|
||||
}
|
||||
if err == nil && tc.shouldError {
|
||||
t.Errorf("interval of %q passed validataion; expected it to fail: %v", input, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue