Skip to content

Commit

Permalink
Fix recursive nesting of derivedFrom (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekthompson authored Jul 5, 2024
1 parent e28501b commit 5c77a3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 29 deletions.
58 changes: 29 additions & 29 deletions cmd/captain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,41 @@ import (
)

var mutuallyExclusiveParsers []parsing.Parser = []parsing.Parser{
new(parsing.DotNetxUnitParser),
new(parsing.GoGinkgoParser),
new(parsing.GoTestParser),
new(parsing.JavaScriptCypressParser),
new(parsing.JavaScriptJestParser),
new(parsing.JavaScriptKarmaParser),
new(parsing.JavaScriptMochaParser),
new(parsing.JavaScriptPlaywrightParser),
new(parsing.PythonPytestParser),
new(parsing.RubyRSpecParser),
parsing.DotNetxUnitParser{},
parsing.GoGinkgoParser{},
parsing.GoTestParser{},
parsing.JavaScriptCypressParser{},
parsing.JavaScriptJestParser{},
parsing.JavaScriptKarmaParser{},
parsing.JavaScriptMochaParser{},
parsing.JavaScriptPlaywrightParser{},
parsing.PythonPytestParser{},
parsing.RubyRSpecParser{},
}

var frameworkParsers map[v1.Framework][]parsing.Parser = map[v1.Framework][]parsing.Parser{
v1.DotNetxUnitFramework: {new(parsing.DotNetxUnitParser)},
v1.ElixirExUnitFramework: {new(parsing.ElixirExUnitParser)},
v1.GoGinkgoFramework: {new(parsing.GoGinkgoParser)},
v1.GoTestFramework: {new(parsing.GoTestParser)},
v1.JavaScriptCucumberFramework: {new(parsing.JavaScriptCucumberJSONParser)},
v1.JavaScriptCypressFramework: {new(parsing.JavaScriptCypressParser)},
v1.JavaScriptJestFramework: {new(parsing.JavaScriptJestParser)},
v1.JavaScriptKarmaFramework: {new(parsing.JavaScriptKarmaParser)},
v1.JavaScriptMochaFramework: {new(parsing.JavaScriptMochaParser)},
v1.JavaScriptPlaywrightFramework: {new(parsing.JavaScriptPlaywrightParser)},
v1.PHPUnitFramework: {new(parsing.PHPUnitParser)},
v1.PythonPytestFramework: {new(parsing.PythonPytestParser)},
v1.PythonUnitTestFramework: {new(parsing.PythonUnitTestParser)},
v1.RubyCucumberFramework: {new(parsing.RubyCucumberParser)},
v1.RubyMinitestFramework: {new(parsing.RubyMinitestParser)},
v1.RubyRSpecFramework: {new(parsing.RubyRSpecParser)},
v1.DotNetxUnitFramework: {parsing.DotNetxUnitParser{}},
v1.ElixirExUnitFramework: {parsing.ElixirExUnitParser{}},
v1.GoGinkgoFramework: {parsing.GoGinkgoParser{}},
v1.GoTestFramework: {parsing.GoTestParser{}},
v1.JavaScriptCucumberFramework: {parsing.JavaScriptCucumberJSONParser{}},
v1.JavaScriptCypressFramework: {parsing.JavaScriptCypressParser{}},
v1.JavaScriptJestFramework: {parsing.JavaScriptJestParser{}},
v1.JavaScriptKarmaFramework: {parsing.JavaScriptKarmaParser{}},
v1.JavaScriptMochaFramework: {parsing.JavaScriptMochaParser{}},
v1.JavaScriptPlaywrightFramework: {parsing.JavaScriptPlaywrightParser{}},
v1.PHPUnitFramework: {parsing.PHPUnitParser{}},
v1.PythonPytestFramework: {parsing.PythonPytestParser{}},
v1.PythonUnitTestFramework: {parsing.PythonUnitTestParser{}},
v1.RubyCucumberFramework: {parsing.RubyCucumberParser{}},
v1.RubyMinitestFramework: {parsing.RubyMinitestParser{}},
v1.RubyRSpecFramework: {parsing.RubyRSpecParser{}},
}

var genericParsers []parsing.Parser = []parsing.Parser{
new(parsing.RWXParser),
new(parsing.JUnitTestsuitesParser),
new(parsing.JUnitTestsuiteParser),
parsing.RWXParser{},
parsing.JUnitTestsuitesParser{},
parsing.JUnitTestsuiteParser{},
}

var invalidSuiteIDRegexp = regexp.MustCompile(`[^a-zA-Z0-9_-]`)
Expand Down
34 changes: 34 additions & 0 deletions test/oss_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
package integration_test

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/bradleyjkemp/cupaloy"
"github.com/google/uuid"
"github.com/rwx-research/captain-cli"
"github.com/rwx-research/captain-cli/test/helpers"

v1 "github.com/rwx-research/captain-cli/internal/testingschema/v1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -1067,6 +1071,36 @@ var _ = Describe(versionedPrefixForQuarantining()+"OSS mode Integration Tests",
Expect(result.exitCode).To(Equal(0))
cupaloy.SnapshotT(GinkgoT(), result.stdout)
})

It("does not add the parsed file to derivedFrom when it's already in the RWX format", func() {
result := runCaptain(captainArgs{
args: []string{"parse", "results", "fixtures/rwx/v1_not_derived.json"},
env: make(map[string]string),
})

Expect(result.exitCode).To(Equal(0))

var testResults v1.TestResults

err := json.NewDecoder(strings.NewReader(result.stdout)).Decode(&testResults)
Expect(err).NotTo(HaveOccurred())
Expect(testResults.DerivedFrom).To(BeNil())
})

It("leaves the derived from contents exactly as it was when it's already in the RWX format", func() {
result := runCaptain(captainArgs{
args: []string{"parse", "results", "fixtures/rwx/v1.json"},
env: make(map[string]string),
})

Expect(result.exitCode).To(Equal(0))

var testResults v1.TestResults

err := json.NewDecoder(strings.NewReader(result.stdout)).Decode(&testResults)
Expect(err).NotTo(HaveOccurred())
Expect(testResults.DerivedFrom[0].Contents).To(Equal("base64encodedoriginalfile"))
})
})
})
})
Expand Down

0 comments on commit 5c77a3c

Please sign in to comment.