@@ -118,6 +118,7 @@ func TestFunctional(t *testing.T) {
118
118
{"DryRun" , validateDryRun },
119
119
{"StatusCmd" , validateStatusCmd },
120
120
{"LogsCmd" , validateLogsCmd },
121
+ {"LogsFileCmd" , validateLogsFileCmd },
121
122
{"MountCmd" , validateMountCmd },
122
123
{"ProfileCmd" , validateProfileCmd },
123
124
{"ServiceCmd" , validateServiceCmd },
@@ -1057,12 +1058,7 @@ func validateConfigCmd(ctx context.Context, t *testing.T, profile string) {
1057
1058
}
1058
1059
}
1059
1060
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 ) {
1066
1062
expectedWords := []string {"apiserver" , "Linux" , "kubelet" , "Audit" , "Last Start" }
1067
1063
switch ContainerRuntime () {
1068
1064
case "docker" :
@@ -1074,12 +1070,46 @@ func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
1074
1070
}
1075
1071
1076
1072
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 )
1079
1075
}
1080
1076
}
1081
1077
}
1082
1078
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
+
1083
1113
// validateProfileCmd asserts "profile" command functionality
1084
1114
func validateProfileCmd (ctx context.Context , t * testing.T , profile string ) {
1085
1115
t .Run ("profile_not_create" , func (t * testing.T ) {
0 commit comments