Skip to content

Commit

Permalink
Create functional integration test for logs --file argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyDev committed May 5, 2021
1 parent 5776597 commit 4051ba5
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestFunctional(t *testing.T) {
{"DryRun", validateDryRun},
{"StatusCmd", validateStatusCmd},
{"LogsCmd", validateLogsCmd},
{"LogsFileCmd", validateLogsFileCmd},
{"MountCmd", validateMountCmd},
{"ProfileCmd", validateProfileCmd},
{"ServiceCmd", validateServiceCmd},
Expand Down Expand Up @@ -1057,12 +1058,7 @@ func validateConfigCmd(ctx context.Context, t *testing.T, profile string) {
}
}

// validateLogsCmd asserts basic "logs" command functionality
func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "logs"))
if err != nil {
t.Errorf("%s failed: %v", rr.Command(), err)
}
func checkSaneLogs(t *testing.T, logs string) {
expectedWords := []string{"apiserver", "Linux", "kubelet", "Audit", "Last Start"}
switch ContainerRuntime() {
case "docker":
Expand All @@ -1074,12 +1070,46 @@ func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
}

for _, word := range expectedWords {
if !strings.Contains(rr.Stdout.String(), word) {
t.Errorf("expected minikube logs to include word: -%q- but got \n***%s***\n", word, rr.Output())
if !strings.Contains(logs, word) {
t.Errorf("expected minikube logs to include word: -%q- but got \n***%s***\n", word, logs)
}
}
}

// validateLogsCmd asserts basic "logs" command functionality
func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "logs"))
if err != nil {
t.Errorf("%s failed: %v", rr.Command(), err)
}

checkSaneLogs(t, rr.Stdout.String())
}

// validateLogsFileCmd asserts "logs --file" command functionality
func validateLogsFileCmd(ctx context.Context, t *testing.T, profile string) {
dname, err := ioutil.TempDir("", profile)
if err != nil {
t.Fatalf("Cannot create temp dir: %v", err)
}
logFileName := filepath.Join(dname, "logs.txt")

rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "logs", "--file", logFileName))
if err != nil {
t.Errorf("%s failed: %v", rr.Command(), err)
}
if rr.Stdout.String() != "" {
t.Errorf("expected empty minikube logs output, but got: \n***%s***\n", rr.Output())
}

logs, err := ioutil.ReadFile(logFileName)
if err != nil {
t.Errorf("Failed to read logs output '%s': %v", logFileName, err)
}

checkSaneLogs(t, string(logs))
}

// validateProfileCmd asserts "profile" command functionality
func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
t.Run("profile_not_create", func(t *testing.T) {
Expand Down

0 comments on commit 4051ba5

Please sign in to comment.