From 90cbd960cd5f311e1f5ba46c70d53bbd1ca9eb37 Mon Sep 17 00:00:00 2001 From: Pavel Simovec Date: Tue, 4 Aug 2020 15:50:36 +0200 Subject: [PATCH] test file extensions --- test/integration/bugs_test.go | 33 +++++++++++++++++++++++++++++++++ test/integration/main_test.go | 8 ++++++++ 2 files changed, 41 insertions(+) diff --git a/test/integration/bugs_test.go b/test/integration/bugs_test.go index fa7e86146..df7f41bb3 100644 --- a/test/integration/bugs_test.go +++ b/test/integration/bugs_test.go @@ -1,6 +1,9 @@ package integration import ( + "fmt" + "regexp" + "strings" "testing" "time" @@ -155,12 +158,42 @@ func latestArchiveContainsEvent(t *testing.T) { } } +//https://bugzilla.redhat.com/show_bug.cgi?id=1840012 +func latestArchiveFilesContainExtensions(t *testing.T) { + suffixes := []string{ + // known file extensions + `\.crt`, + `\.json`, + `\.log`, + // exceptions - files without extension + `/config`, + `/id`, + `/invoker`, + `/metrics`, + `/version`, + } + pattern := fmt.Sprintf(`(%s)$`, strings.Join(suffixes, "|")) + regex, err := regexp.Compile(pattern) + e(t, err, "failed to compile pattern") + archiveFiles := latestArchiveFiles(t) + t.Log(strings.Join(archiveFiles, "\n")) + if len(archiveFiles) == 0 { + t.Fatal("No files in archive to check") + } + for _, fileName := range archiveFiles { + if !regex.MatchString(fileName) { + t.Errorf(`file "%s" does not match pattern "%s"`, fileName, pattern) + } + } +} + func TestCollectingAfterDegradingOperator(t *testing.T) { defer ChangeReportTimeInterval(t, 1)() defer degradeOperatorMonitoring(t)() checkPodsLogs(t, clientset, `Wrote \d+ records to disk in \d+`, true) t.Run("Logs", latestArchiveContainsPodLogs) t.Run("Event", latestArchiveContainsEvent) + t.Run("FileExtensions", latestArchiveFilesContainExtensions) } // https://bugzilla.redhat.com/show_bug.cgi?id=1782151 diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 7dc5695c6..7fb50b00a 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -354,6 +354,14 @@ func ChangeReportTimeInterval(t *testing.T, minutes time.Duration) func(){ return func(){ changeReportTimeInterval(t, previousInterval) } } +func latestArchiveFiles(t *testing.T) []string { + insightsPod := findPod(t, clientset, "openshift-insights", "insights-operator") + archiveLogFiles := `tar tf $(ls -dtr /var/lib/insights-operator/* | tail -1)` + stdout, _, _ := ExecCmd(t, clientset, insightsPod.Name, "openshift-insights", archiveLogFiles, nil) + stdout = strings.TrimSpace(stdout) + return strings.Split(stdout, "\n") +} + func latestArchiveContainsFiles(t *testing.T, pattern string) (int, error) { insightsPod := findPod(t, clientset, "openshift-insights", "insights-operator") hasLatestArchiveLogs := fmt.Sprintf(`tar tf $(ls -dtr /var/lib/insights-operator/* | tail -1)|grep -c "%s"`, pattern)