Skip to content

Commit 2766d66

Browse files
committed
added testing for auto-pause-interval validation
1 parent 8224790 commit 2766d66

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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 {

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"
@@ -888,3 +889,29 @@ func TestValidateGPUs(t *testing.T) {
888889
}
889890
}
890891
}
892+
893+
func TestValidateAutoPause(t *testing.T) {
894+
tests := []struct {
895+
interval string
896+
shouldError bool
897+
}{
898+
{"1m0s", false},
899+
{"5m", false},
900+
{"1s", false},
901+
{"0s", true},
902+
{"-2m", true},
903+
}
904+
for _, tc := range tests {
905+
input, err := time.ParseDuration(tc.interval)
906+
if err != nil {
907+
t.Fatalf("test has an invalid input duration of %q", tc.interval)
908+
}
909+
err = validateAutoPauseInterval(input)
910+
if err != nil && !tc.shouldError {
911+
t.Errorf("interval of %q failed validation; expected it to pass: %v", input, err)
912+
}
913+
if err == nil && tc.shouldError {
914+
t.Errorf("interval of %q passed validataion; expected it to fail: %v", input, err)
915+
}
916+
}
917+
}

0 commit comments

Comments
 (0)