Skip to content

Commit

Permalink
Xcresult3 (#90)
Browse files Browse the repository at this point in the history
* xcresult format 3 converter

* restucture xcresult3 package

* models test

* structs broken into multiple files, attachment image export added

* removed unnecessary comment

* xcresult converters detect func update

* dep update

* import new xcresult converter

* dep update

* errcheck fix

* some debug logs

* some more debug logging

* debug log fix, document parsing fix

* version conversation fix

* do not fail in case of test report issues

* struct indent fix, error logging fix

* check if xcresulttool available
  • Loading branch information
godrei authored Jun 17, 2019
1 parent f1ce02d commit 79d467e
Show file tree
Hide file tree
Showing 19 changed files with 1,152 additions and 26 deletions.
92 changes: 79 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,16 @@ func main() {

testResults, err := test.ParseTestResults(config.TestDeployDir)
if err != nil {
fail("Error during parsing test results: ", err)
}

log.Printf("- uploading (%d) test results", len(testResults))
log.Warnf("Error during parsing test results: ", err)
} else {
log.Printf("- uploading (%d) test results", len(testResults))

if err := testResults.Upload(config.AddonAPIToken, config.AddonAPIBaseURL, config.AppSlug, config.BuildSlug); err != nil {
fail("Failed to upload test results: ", err)
if err := testResults.Upload(config.AddonAPIToken, config.AddonAPIBaseURL, config.AppSlug, config.BuildSlug); err != nil {
log.Warnf("Failed to upload test results: ", err)
} else {
log.Donef("Success")
}
}

log.Donef("Success")
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/converters/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package converters
import (
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/converters/junitxml"
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/converters/xcresult"
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/converters/xcresult3"
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/junit"
)

Expand All @@ -20,6 +21,7 @@ type Intf interface {
var converters = []Intf{
&junitxml.Converter{},
&xcresult.Converter{},
&xcresult3.Converter{},
}

// List lists all supported converters
Expand Down
11 changes: 8 additions & 3 deletions test/converters/xcresult/xcresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package xcresult

import (
"path/filepath"
"strings"

"github.com/bitrise-io/go-utils/fileutil"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/junit"
"howett.net/plist"
)
Expand All @@ -19,8 +19,13 @@ type Converter struct {
func (h *Converter) Detect(files []string) bool {
h.files = files
for _, file := range h.files {
if strings.HasSuffix(file, ".xcresult") {
h.testSummariesPlistPath = filepath.Join(file, "TestSummaries.plist")
if filepath.Ext(file) == ".xcresult" {
testSummariesPlistPath := filepath.Join(file, "TestSummaries.plist")
if exist, err := pathutil.IsPathExists(testSummariesPlistPath); err != nil || exist == false {
continue
}

h.testSummariesPlistPath = testSummariesPlistPath
return true
}
}
Expand Down
90 changes: 90 additions & 0 deletions test/converters/xcresult3/action_invocation_record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package xcresult3

import (
"fmt"
"strings"
)

// ActionsInvocationRecord ...
type ActionsInvocationRecord struct {
Actions struct {
Values []struct {
ActionResult struct {
TestsRef struct {
ID struct {
Value string `json:"_value"`
} `json:"id"`
} `json:"testsRef"`
} `json:"actionResult"`
} `json:"_values"`
} `json:"actions"`

Issues Issues `json:"issues"`
}

// Issues ...
type Issues struct {
TestFailureSummaries TestFailureSummaries `json:"testFailureSummaries"`
}

// TestFailureSummaries ...
type TestFailureSummaries struct {
Values []TestFailureSummary `json:"_values"`
}

// TestFailureSummary ...
type TestFailureSummary struct {
DocumentLocationInCreatingWorkspace DocumentLocationInCreatingWorkspace `json:"documentLocationInCreatingWorkspace"`
Message Message `json:"message"`
ProducingTarget ProducingTarget `json:"producingTarget"`
TestCaseName TestCaseName `json:"testCaseName"`
}

// URL ...
type URL struct {
Value string `json:"_value"`
}

// DocumentLocationInCreatingWorkspace ...
type DocumentLocationInCreatingWorkspace struct {
URL URL `json:"url"`
}

// ProducingTarget ...
type ProducingTarget struct {
Value string `json:"_value"`
}

// TestCaseName ...
type TestCaseName struct {
Value string `json:"_value"`
}

// Message ...
type Message struct {
Value string `json:"_value"`
}

// failure returns the ActionTestSummaryGroup's failure reason from the ActionsInvocationRecord.
func (r ActionsInvocationRecord) failure(test ActionTestSummaryGroup) string {
target, testCase := test.producingTargetAndTestCaseName()
for _, failureSummary := range r.Issues.TestFailureSummaries.Values {
if failureSummary.ProducingTarget.Value == target && failureSummary.TestCaseName.Value == testCase {
file, line := failureSummary.fileAndLineNumber()
return fmt.Sprintf("%s:%s - %s", file, line, failureSummary.Message.Value)
}
}
return ""
}

// fileAndLineNumber unwraps the file path and line number descriptor from a given ActionTestSummaryGroup's.
func (s TestFailureSummary) fileAndLineNumber() (file string, line string) {
// file:\/\/\/Users\/bitrisedeveloper\/Develop\/ios\/Xcode11Test\/Xcode11TestUITests\/Xcode11TestUITests.swift#CharacterRangeLen=0&EndingLineNumber=42&StartingLineNumber=42
if s.DocumentLocationInCreatingWorkspace.URL.Value != "" {
i := strings.LastIndex(s.DocumentLocationInCreatingWorkspace.URL.Value, "#")
if i > -1 && i+1 < len(s.DocumentLocationInCreatingWorkspace.URL.Value) {
return s.DocumentLocationInCreatingWorkspace.URL.Value[:i], s.DocumentLocationInCreatingWorkspace.URL.Value[i+1:]
}
}
return
}
Loading

0 comments on commit 79d467e

Please sign in to comment.