added testing for auto-pause-interval validation

pull/17936/head
Steven Powell 2024-01-12 13:36:18 -08:00
parent a5e44b1d54
commit 560d3aa340
2 changed files with 28 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
}
}
}