Skip to content

Commit

Permalink
added testing for auto-pause-interval validation
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jan 12, 2024
1 parent 8224790 commit 2766d66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/blang/semver/v4"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -888,3 +889,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)
}
}
}

0 comments on commit 2766d66

Please sign in to comment.