|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "regexp" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +// stderrAllow are regular expressions acceptable to find in normal stderr |
| 13 | +var stderrAllow = []string{ |
| 14 | + // kubectl out of date warning |
| 15 | + `kubectl`, |
| 16 | + // slow docker warning |
| 17 | + `slow|long time|Restarting the docker service may improve`, |
| 18 | + // don't care if we can't push images to other profiles |
| 19 | + `cache_images.go:.*error getting status`, |
| 20 | + // don't care if we can't push images to other profiles which are deleted. |
| 21 | + `cache_images.go:.*Failed to load profile`, |
| 22 | + // "! 'docker' driver reported a issue that could affect the performance." |
| 23 | + `docker.*issue.*performance`, |
| 24 | + // "* Suggestion: enable overlayfs kernel module on your Linux" |
| 25 | + `Suggestion.*overlayfs`, |
| 26 | + // "! docker is currently using the btrfs storage driver, consider switching to overlay2 for better performance" |
| 27 | + `docker.*btrfs storage driver`, |
| 28 | + // jenkins VMs (debian 9) cgoups don't allow setting memory |
| 29 | + `Your cgroup does not allow setting memory.`, |
| 30 | + // progress bar output |
| 31 | + ` > .*`, |
| 32 | + // Warning of issues with specific Kubernetes versions |
| 33 | + `Kubernetes .* has a known `, |
| 34 | + `For more information, see`, |
| 35 | +} |
| 36 | + |
| 37 | +// stderrAllowRe combines rootCauses into a single regex |
| 38 | +var stderrAllowRe = regexp.MustCompile(strings.Join(stderrAllow, "|")) |
| 39 | + |
| 40 | +// checkSpam checks standard output and standard error for unexpected spam |
| 41 | +func checkSpam(t *testing.T, stdout, stderr string) { |
| 42 | + for _, line := range strings.Split(stderr, "\n") { |
| 43 | + if stderrAllowRe.MatchString(line) { |
| 44 | + t.Logf("acceptable stderr: %q", line) |
| 45 | + continue |
| 46 | + } |
| 47 | + |
| 48 | + if len(strings.TrimSpace(line)) > 0 { |
| 49 | + t.Errorf("unexpected stderr: %q", line) |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + for _, line := range strings.Split(stdout, "\n") { |
| 54 | + keywords := []string{"error", "fail", "warning", "conflict"} |
| 55 | + for _, keyword := range keywords { |
| 56 | + if strings.Contains(line, keyword) { |
| 57 | + t.Errorf("unexpected %q in stdout: %q", keyword, line) |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func getLogFiles(logDir string, command string) ([]string, error) { |
| 64 | + return filepath.Glob(filepath.Join(logDir, fmt.Sprintf("minikube_%s*", command))) |
| 65 | +} |
| 66 | + |
| 67 | +func checkLogFileCount(command string, logDir string, expectedNumberOfLogFiles int) error { |
| 68 | + // get log files generated above |
| 69 | + logFiles, err := getLogFiles(logDir, command) |
| 70 | + if err != nil { |
| 71 | + return fmt.Errorf("failed to get new log files for command %s : %v", command, err) |
| 72 | + } |
| 73 | + |
| 74 | + if len(logFiles) != expectedNumberOfLogFiles { |
| 75 | + return fmt.Errorf("Running cmd %q resulted in %d log file(s); expected: %d", command, len(logFiles), expectedNumberOfLogFiles) |
| 76 | + } |
| 77 | + |
| 78 | + return nil |
| 79 | +} |
| 80 | + |
| 81 | +// cleanupLogFiles removes logfiles generated during testing |
| 82 | +func cleanupLogFiles(t *testing.T, logFiles []string) { |
| 83 | + t.Logf("Cleaning up %d logfile(s) ...", len(logFiles)) |
| 84 | + for _, logFile := range logFiles { |
| 85 | + if err := os.Remove(logFile); err != nil { |
| 86 | + t.Logf("failed to cleanup log file: %s : %v", logFile, err) |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments