Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test if files in insights archive have extension set #150

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/integration/bugs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package integration

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

Expand All @@ -9,6 +11,14 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
)

const knownFileSuffixesInsideArchiveRegex string = `(`+
// known file extensions
`\.(crt|json|log)` +
`|` +
// exceptions - file names without extension #
`(\/|^)(config|id|invoker|metrics|version)` +
`)$`

// https://bugzilla.redhat.com/show_bug.cgi?id=1750665
// https://bugzilla.redhat.com/show_bug.cgi?id=1753755
func TestDefaultUploadFrequency(t *testing.T) {
Expand Down Expand Up @@ -155,12 +165,29 @@ func latestArchiveContainsEvent(t *testing.T) {
}
}

//https://bugzilla.redhat.com/show_bug.cgi?id=1840012
func latestArchiveFilesContainExtensions(t *testing.T) {
regex, err := regexp.Compile(knownFileSuffixesInsideArchiveRegex)
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, knownFileSuffixesInsideArchiveRegex)
}
}
}

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