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

fix: make test case logs collapsed by default #148

Merged
merged 2 commits into from
Nov 26, 2024
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
21 changes: 2 additions & 19 deletions cmd/oci/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/konflux-ci/qe-tools/pkg/oci"
"github.com/konflux-ci/qe-tools/pkg/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -119,7 +120,7 @@ Examples:

// If repo is specified, call helper function to download from a single repository
if opts.repo != "" {
repo, tag, err := parseRepoAndTag(opts.repo)
repo, tag, err := utils.ParseRepoAndTag(opts.repo)
if err != nil {
return err
}
Expand Down Expand Up @@ -192,24 +193,6 @@ Examples:
},
}

// parseRepoAndTag extracts the repository and tag from the given repo flag.
func parseRepoAndTag(repoFlag string) (string, string, error) {
// Ensure the repoFlag starts with 'quay.io/'
if !strings.HasPrefix(repoFlag, "quay.io/") {
return "", "", fmt.Errorf("the repository must start with 'quay.io/'")
}

// Remove 'quay.io/' prefix and split the repo and tag using the ':' character
repoFlag = strings.TrimPrefix(repoFlag, "quay.io/")
parts := strings.SplitN(repoFlag, ":", 2)

if len(parts) != 2 {
return "", "", fmt.Errorf("tag is missing in the repo flag")
}

return parts[0], parts[1], nil
}

// parseDuration handles the custom duration format
func parseDuration(since string) (time.Duration, error) {
if len(since) > 1 && since[len(since)-1] == 'd' {
Expand Down
22 changes: 16 additions & 6 deletions pkg/oci/artifact_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"time"

"github.com/konflux-ci/qe-tools/pkg/utils"
)

// NewArtifactScanner creates a new instance of ArtifactScanner.
Expand Down Expand Up @@ -40,11 +42,19 @@ func (as *ArtifactScanner) Run() error {
}

func (as *ArtifactScanner) pullAndExtractOciArtifact() error {
app := "oras"
args := []string{"pull", as.config.OciArtifactReference, "--output", as.artifactDirPath}
// #nosec G204
cmd := exec.Command(app, args...)
if err := cmd.Run(); err != nil {
cacheDir, err := os.MkdirTemp("", "")
if err != nil {
return err
}
ctrl, err := NewController(as.artifactDirPath, cacheDir)
if err != nil {
return err
}
repo, tag, err := utils.ParseRepoAndTag(as.config.OciArtifactReference)
if err != nil {
return err
}
if err := ctrl.ProcessTag(repo, tag, time.Now().Format(time.RFC1123)); err != nil {
return err
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/testresults/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func extractFailedTestCasesBody(f FailedTestCasesReport) (failedTestCasesBody []
case tc.Status == "timedout":
tcMessage = returnContentWrappedInDropdown(dropdownSummaryString, tc.SystemErr)
case tc.Failure != nil:
tcMessage = "```\n" + tc.Failure.Message + "\n```"
tcMessage = returnContentWrappedInDropdown(dropdownSummaryString, tc.Failure.Message)
default:
tcMessage = "```\n" + tc.Error.Message + "\n```"
tcMessage = returnContentWrappedInDropdown(dropdownSummaryString, tc.Error.Message)
}

testCaseEntry := "* :arrow_right: " + "[**`" + tc.Status + "`**] " + tc.Name + "\n" + tcMessage
testCaseEntry := ":arrow_right: " + "[**`" + tc.Status + "`**] " + tc.Name + tcMessage
failedTestCasesBody = append(failedTestCasesBody, testCaseEntry)
}
return
Expand Down Expand Up @@ -64,5 +64,5 @@ func GetFormattedReport(report FailedTestCasesReport) (formattedReport string) {
}

func returnContentWrappedInDropdown(summary, content string) string {
return "<details><summary>" + summary + "</summary><br><pre>" + content + "</pre></details>"
return "<details><summary>" + summary + "</summary><br><pre>" + content + "</pre></details>\n\n---"
}
24 changes: 24 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package utils

import (
"fmt"
"strings"
)

// ParseRepoAndTag extracts the quay.io repository and tag from the given repo flag.
func ParseRepoAndTag(repoFlag string) (string, string, error) {
// Ensure the repoFlag starts with 'quay.io/'
if !strings.HasPrefix(repoFlag, "quay.io/") {
return "", "", fmt.Errorf("the repository must start with 'quay.io/'")
}

// Remove 'quay.io/' prefix and split the repo and tag using the ':' character
repoFlag = strings.TrimPrefix(repoFlag, "quay.io/")
parts := strings.SplitN(repoFlag, ":", 2)

if len(parts) != 2 {
return "", "", fmt.Errorf("tag is missing in the repo flag")
}

return parts[0], parts[1], nil
}