Skip to content

Commit 560d3aa

Browse files
committed
added testing for auto-pause-interval validation
1 parent a5e44b1 commit 560d3aa

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: cmd/minikube/cmd/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ func validateCPUCount(drvName string) {
12501250
}
12511251

12521252
// validateFlags validates the supplied flags against known bad combinations
1253-
func validateFlags(cmd *cobra.Command, drvName string) {
1253+
func validateFlags(cmd *cobra.Command, drvName string) { //nolint:gocyclo
12541254
if cmd.Flags().Changed(humanReadableDiskSize) {
12551255
err := validateDiskSize(viper.GetString(humanReadableDiskSize))
12561256
if err != nil {

Diff for: cmd/minikube/cmd/start_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"strings"
2222
"testing"
23+
"time"
2324

2425
"github.com/blang/semver/v4"
2526
"github.com/spf13/cobra"
@@ -886,3 +887,29 @@ func TestValidateGPUs(t *testing.T) {
886887
}
887888
}
888889
}
890+
891+
func TestValidateAutoPause(t *testing.T) {
892+
tests := []struct {
893+
interval string
894+
shouldError bool
895+
}{
896+
{"1m0s", false},
897+
{"5m", false},
898+
{"1s", false},
899+
{"0s", true},
900+
{"-2m", true},
901+
}
902+
for _, tc := range tests {
903+
input, err := time.ParseDuration(tc.interval)
904+
if err != nil {
905+
t.Fatalf("test has an invalid input duration of %q", tc.interval)
906+
}
907+
err = validateAutoPauseInterval(input)
908+
if err != nil && !tc.shouldError {
909+
t.Errorf("interval of %q failed validation; expected it to pass: %v", input, err)
910+
}
911+
if err == nil && tc.shouldError {
912+
t.Errorf("interval of %q passed validataion; expected it to fail: %v", input, err)
913+
}
914+
}
915+
}

0 commit comments

Comments
 (0)