Skip to content

Commit

Permalink
Merge pull request #1933 from yasun1/pre-check
Browse files Browse the repository at this point in the history
[OCM-7442] Get the test case IDs
  • Loading branch information
openshift-merge-bot[bot] committed Apr 16, 2024
2 parents dd63b70 + fffc954 commit 4e2c4fe
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/ci/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type TestConfig struct {
ClusterDetailFile string
ClusterInstallLogArtifactFile string
ClusterAdminFile string
TestFocusFile string
GlobalENV *GlobalENVVariables
}
type GlobalENVVariables struct {
Expand Down Expand Up @@ -70,6 +71,7 @@ func init() {
Test.ClusterDetailFile = path.Join(Test.OutputDir, "cluster-detail.json")
Test.ClusterInstallLogArtifactFile = path.Join(Test.ArtifactDir, ".install.log")
Test.ClusterAdminFile = path.Join(Test.ArtifactDir, ".admin")
Test.TestFocusFile = path.Join(Test.RootDir, "tests", "ci", "data", "commit-focus")

waitingTime, err := strconv.Atoi(common.ReadENVWithDefaultValue("CLUSTER_TIMEOUT", "60"))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tests/ci/labels/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
. "github.com/onsi/ginkgo/v2"
)

// Pre check
var E2ECommit = Label("e2e-commit")

// day1/day1-post and day2
var Day1 = Label("day1")
var Day1Prepare = Label("day1-prepare")
Expand Down
22 changes: 22 additions & 0 deletions tests/e2e/e2e_pre_check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package e2e

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/openshift/rosa/tests/ci/labels"
"github.com/openshift/rosa/tests/utils/exec/rosacli"
)

var _ = Describe("PreCheck", func() {
It("commits-focus", labels.E2ECommit, func() {
author, err := rosacli.GetCommitAuthor()
Expect(err).ToNot(HaveOccurred())

focus, err := rosacli.GetCommitFoucs()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("[%s] Focus: %v\n", author, focus)
})
})
2 changes: 1 addition & 1 deletion tests/utils/exec/rosacli/cmd_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (r *runner) RunCMD(command []string) (bytes.Buffer, error) {
cmd.Stderr = cmd.Stdout

err = cmd.Run()
Logger.Infof("Get Combining Stdout and Stder is :\n%s", output.String())
Logger.Infof("Get Combining Stdout and Stder is : %s", output.String())

return output, err

Expand Down
49 changes: 49 additions & 0 deletions tests/utils/exec/rosacli/pr_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package rosacli

import (
"regexp"
"strings"

"github.com/openshift/rosa/tests/ci/config"
common "github.com/openshift/rosa/tests/utils/common"
)

func GetCommitAuthor() (string, error) {
command := "git log -n 1 --pretty=format:%an"
runner := NewRunner()

output, err := runner.RunCMD(strings.Split(command, " "))
if err != nil {
return "", err
}

return output.String(), nil
}

func GetCommitFoucs() (string, error) {
command := "git log -n 1 --pretty=format:%s"
runner := NewRunner()

output, err := runner.RunCMD(strings.Split(command, " "))
if err != nil {
return "", err
}
theStrSlice := strings.Split(output.String(), " ")

var tcIDs []string
reg := regexp.MustCompile(`(id:.*)`)
for _, theStr := range theStrSlice {
m := reg.FindAllString(theStr, -1)
if len(m) > 0 {
for _, idStr := range m {
idStr = strings.Split(idStr, "id:")[1]
ids := strings.Split(idStr, ",")
tcIDs = append(tcIDs, ids...)
}
}
}

focus := strings.Join(tcIDs, "|")
_, err = common.CreateFileWithContent(config.Test.TestFocusFile, focus)
return focus, err
}

0 comments on commit 4e2c4fe

Please sign in to comment.