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

Ability to apply a transformation to the "testsuite" name in junit #50

Closed
ijc opened this issue Mar 21, 2019 · 3 comments · Fixed by #70
Closed

Ability to apply a transformation to the "testsuite" name in junit #50

ijc opened this issue Mar 21, 2019 · 3 comments · Fixed by #70
Labels
enhancement New feature or request

Comments

@ijc
Copy link

ijc commented Mar 21, 2019

If I run tests on a package github.com/ijc/foo/... using -junitfile then I get results with:

<testsuite tests="33" failures="0" time="0.000000" name="github.com/ijc/foo/bar">
...
<testsuite tests="33" failures="0" time="0.000000" name="github.com/ijc/foo/baz">

...so far so good.

However if I feed this into Jenkins it creates me a directory named "github" and within that there are two entries "com/ijc/foo/bar" and "com/ijc/foo/baz", this is not really a desirable presentation.

It would be useful if gotestsum could allow fiddling with the name somehow. My preference would be to allow specifying a (common) prefix to be dropped from all the suite names (e.g. I would likely choose to drop github.com/ijc/foo/). A variant of that would be a -p«N» option (cf patch(1)) to strip «n» path elements.

I'm not sure if other transformations might be useful/better e.g. tr . - or some sort of escaping.

Just stripping a prefix has the benefit of being nice and simple I think.

@dnephin dnephin added the enhancement New feature or request label Mar 22, 2019
@dnephin
Copy link
Member

dnephin commented Mar 22, 2019

Do you have a link to the jenkins plugin that does this? I wonder what logic it uses to make the directory structure. I guess Java class paths are separated by dots, which is why it has done this? If that is the case another option might be to convert the path into something that resembles a valid java path (ex: githubcom.ijc.foo

This change (#49) was made recently (v0.3.4) to improve integration with CircleCI. I wonder if that will cause any problems with the jenkins plugin.

Generally making the junit report integrate better with CI systems makes sense to me.

@ijc
Copy link
Author

ijc commented Mar 22, 2019

Yes, I suspect this is something to do with Java class path separators.

I'm using a hosted Jenkins so the junit plugin was there already, I believe it is the standard one though which is https://wiki.jenkins.io/display/JENKINS/JUnit+Plugin.

Switching to githubcom.ijc.foo I think would work, although it would mean a three level deep thing in Jenkins I suspect (githubcomijcfoo, then plus the subpackages in my project), but I think that's then "working as Jenkins designed" and it is at least better than githubcom/ijc/foo. I would still prefer the prefix strip option but could live with your proposal.

@ijc
Copy link
Author

ijc commented Mar 27, 2019

I found a (very gross) workaround:

gotestsum --raw-command -- sh -c 'go list ./... | sed -e "s,^github.com/ijc/foo/\?,/,g" | xargs -I{} -n1 go tool test2json -p unit{} -t go test -v github.com/ijc/foo{}'

(the /\? thing in the sed is to turn the line matching ^github.com/ijc/foo$ into / and not the empty string so that xargs will actual emit something, so we end up with -p unit/ or -p unit/subpackage etc)

ijc pushed a commit to ijc/docker-app that referenced this issue Apr 1, 2019
Jenkins interprets the default as nested folders `github` → `com/docker/app`
(presumably due to thinking it is using Java style naming).

In gotestyourself/gotestsum#50 I requested support
for something in `gotestsum` itself but for now this will do.

Signed-off-by: Ian Campbell <[email protected]>
ijc pushed a commit to ijc/docker-app that referenced this issue Apr 1, 2019
Jenkins interprets the default as nested folders `github` → `com/docker/app`
(presumably due to thinking it is using Java style naming).

In gotestyourself/gotestsum#50 I requested support
for something in `gotestsum` itself but for now this will do.

Signed-off-by: Ian Campbell <[email protected]>
ijc pushed a commit to ijc/docker-app that referenced this issue Apr 1, 2019
Jenkins interprets the default as nested folders `github` → `com/docker/app`
(presumably due to thinking it is using Java style naming).

In gotestyourself/gotestsum#50 I requested support
for something in `gotestsum` itself but for now this will do.

Signed-off-by: Ian Campbell <[email protected]>
ijc pushed a commit to ijc/docker-app that referenced this issue Apr 1, 2019
Jenkins interprets the default as nested folders `github` → `com/docker/app`
(presumably due to thinking it is using Java style naming).

In gotestyourself/gotestsum#50 I requested support
for something in `gotestsum` itself but for now this will do.

Signed-off-by: Ian Campbell <[email protected]>
ijc pushed a commit to ijc/docker-app that referenced this issue Apr 2, 2019
Jenkins interprets the default as nested folders `github` → `com/docker/app`
(presumably due to thinking it is using Java style naming).

In gotestyourself/gotestsum#50 I requested support
for something in `gotestsum` itself but for now this will do.

Signed-off-by: Ian Campbell <[email protected]>
ijc pushed a commit to ijc/gotestsum that referenced this issue Apr 4, 2019
Fixes gotestyourself#50.

I would use this with e.g. `--junit-striplevels=2` and
`--junitfile-prefix=unit/app` to replace `github.com/docker/app` with
`app/unit` as the root path and I'd vary `unit` for other test runs (e.g. with
coverage, with experimental enabled etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants