Skip to content

Commit

Permalink
validate test hierarchy, fail if json report is broken due bug: golan…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kudasov committed Apr 22, 2020
1 parent 96c9f3e commit d05c116
Show file tree
Hide file tree
Showing 7 changed files with 8,159 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go install cmd/go-test-rp.go
| Param key | Default | Description |
| ------------- | ---------------------------- | ---------------------- |
| --json_report | - | go test json file |
| --log_level | info | agent log level |
| --rp_project | - | RP project name |
| --rp_run_name | - | RP run name |
| --rp_run_desc | - | RP run description |
Expand Down
6 changes: 5 additions & 1 deletion cmd/go-test-rp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

func main() {
jsonReportPath := flag.String("json_report", "", "path to go test json report")
loglevel := flag.String("log_level", "info", "logging level: debug, info")
runName := flag.String("rp_run_name", "", "testrun name")
runDesc := flag.String("rp_run_desc", "", "testrun description")
rpProject := flag.String("rp_project", "", "report portal project")
Expand All @@ -22,6 +23,9 @@ func main() {
force := flag.Bool("force", false, "if true, exit code will be 0 even if errors")
dumptransport := flag.Bool("dumptransport", false, "debug http with bodies")
flag.Parse()
if *loglevel == "" {
log.Fatal("provide log level: debug, info")
}
if *jsonReportPath == "" {
log.Fatal("provide path to go test json report file using --json_report ex.json")
}
Expand Down Expand Up @@ -51,7 +55,7 @@ func main() {
}
}

a := integration.NewRPAgent(*rpUrl, *rpProject, *rpToken, *btsProject, *btsUrl, *dumptransport, integration.WithForce(*force))
a := integration.NewRPAgent(*rpUrl, *rpProject, *rpToken, *btsProject, *btsUrl, *loglevel, *dumptransport, integration.WithForce(*force))
a.Report(*jsonReportPath, *runName, *runDesc, *rpProject, *tagStr)
if a.JsonReportErrorsNum > 0 && !*force {
// if any errors of broken tests are present fail build
Expand Down
16 changes: 14 additions & 2 deletions integration/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
)

// Creates new Report Portal agent
func NewRPAgent(baseUrl string, project string, token string, btsProject string, btsUrl string, dumptransport bool, options ...func(*RPAgent) error) *RPAgent {
func NewRPAgent(baseUrl string, project string, token string, btsProject string, btsUrl string, loglevel string, dumptransport bool, options ...func(*RPAgent) error) *RPAgent {
rpa := &RPAgent{
Events: make([]*TestEvent, 0),
BtsProject: btsProject,
Expand All @@ -44,7 +44,7 @@ func NewRPAgent(baseUrl string, project string, token string, btsProject string,
Force: false,
MaxRps: 400,
TestLogBatch: make([]rpgoclient.LogPayload, 0),
l: NewLogger("info"),
l: NewLogger(loglevel),
}
if rpa.c == nil {
rpa.c = rpgoclient.New(baseUrl, project, token, btsProject, btsUrl, dumptransport)
Expand Down Expand Up @@ -170,6 +170,17 @@ func RPTestData(tpath string, testObj *TestObject) (name string, desc string) {
return
}

func (m *RPAgent) validateHierarchy(testObjects []*TestObject, tosByName map[string]*TestObject) {
for _, to := range testObjects {
for _, tpath := range to.FullPathCrumbs {
_, ok := tosByName[tpath]
if !ok {
m.l.Fatalf("invalid test hierarchy in json report (see bug: https://github.com/golang/go/issues/35180), object %s not found, exiting", tpath)
}
}
}
}

// startEntitiesHierarchy starts RP test entities hierarchically, using test path
func (m *RPAgent) startEntitiesHierarchy(
launchData rpgoclient.StartLaunchResponse,
Expand Down Expand Up @@ -261,6 +272,7 @@ func (m *RPAgent) Report(jsonFilename string, runName string, runDesc string, pr
events := parseEventsBatch(f)
testObjects, tosByName := eventsToObjects(events)
m.l.Infof(InfoColor, fmt.Sprintf("sending report to: %s, project: %s", m.c.GetBaseUrl(), m.c.GetProject()))
m.validateHierarchy(testObjects, tosByName)
earliestInReport, latestInReport := getTimeBounds(events)
launchData, err := m.c.StartLaunch(runName, runDesc, earliestInReport.Format(time.RFC3339), parseTags(tag), "DEFAULT")
if err != nil {
Expand Down
Loading

0 comments on commit d05c116

Please sign in to comment.