Skip to content

Commit

Permalink
test file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
psimovec committed Aug 4, 2020
1 parent c7d2283 commit 90cbd96
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/integration/bugs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package integration

import (
"fmt"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 90cbd96

Please sign in to comment.