Skip to content

Commit 4051ba5

Browse files
committed
Create functional integration test for logs --file argument.
1 parent 5776597 commit 4051ba5

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

test/integration/functional_test.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestFunctional(t *testing.T) {
118118
{"DryRun", validateDryRun},
119119
{"StatusCmd", validateStatusCmd},
120120
{"LogsCmd", validateLogsCmd},
121+
{"LogsFileCmd", validateLogsFileCmd},
121122
{"MountCmd", validateMountCmd},
122123
{"ProfileCmd", validateProfileCmd},
123124
{"ServiceCmd", validateServiceCmd},
@@ -1057,12 +1058,7 @@ func validateConfigCmd(ctx context.Context, t *testing.T, profile string) {
10571058
}
10581059
}
10591060

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

10761072
for _, word := range expectedWords {
1077-
if !strings.Contains(rr.Stdout.String(), word) {
1078-
t.Errorf("expected minikube logs to include word: -%q- but got \n***%s***\n", word, rr.Output())
1073+
if !strings.Contains(logs, word) {
1074+
t.Errorf("expected minikube logs to include word: -%q- but got \n***%s***\n", word, logs)
10791075
}
10801076
}
10811077
}
10821078

1079+
// validateLogsCmd asserts basic "logs" command functionality
1080+
func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
1081+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "logs"))
1082+
if err != nil {
1083+
t.Errorf("%s failed: %v", rr.Command(), err)
1084+
}
1085+
1086+
checkSaneLogs(t, rr.Stdout.String())
1087+
}
1088+
1089+
// validateLogsFileCmd asserts "logs --file" command functionality
1090+
func validateLogsFileCmd(ctx context.Context, t *testing.T, profile string) {
1091+
dname, err := ioutil.TempDir("", profile)
1092+
if err != nil {
1093+
t.Fatalf("Cannot create temp dir: %v", err)
1094+
}
1095+
logFileName := filepath.Join(dname, "logs.txt")
1096+
1097+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "logs", "--file", logFileName))
1098+
if err != nil {
1099+
t.Errorf("%s failed: %v", rr.Command(), err)
1100+
}
1101+
if rr.Stdout.String() != "" {
1102+
t.Errorf("expected empty minikube logs output, but got: \n***%s***\n", rr.Output())
1103+
}
1104+
1105+
logs, err := ioutil.ReadFile(logFileName)
1106+
if err != nil {
1107+
t.Errorf("Failed to read logs output '%s': %v", logFileName, err)
1108+
}
1109+
1110+
checkSaneLogs(t, string(logs))
1111+
}
1112+
10831113
// validateProfileCmd asserts "profile" command functionality
10841114
func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
10851115
t.Run("profile_not_create", func(t *testing.T) {

0 commit comments

Comments
 (0)