-
Notifications
You must be signed in to change notification settings - Fork 340
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
Default checks name to be ' / '-joined enclosing blocks names #211
Default checks name to be ' / '-joined enclosing blocks names #211
Conversation
src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-checksName.html
Outdated
Show resolved
Hide resolved
src/main/resources/hudson/tasks/junit/pipeline/JUnitResultsStep/help-checksName.html
Outdated
Show resolved
Hide resolved
// If we haven't been provided with a checks name, and we have pipeline test details, set the checks name | ||
// to be a ' / '-joined string of the enclosing blocks names. JUnitChecksPublisher will handle defaults if | ||
// checksName ends up being empty or null | ||
String checksName = task.getChecksName() != null || pipelineTestDetails == null ? task.getChecksName() : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example PR where this has been tested? both custom checks name and no override
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to spend some quality time with mockito to see if I can get the checks tests testing more of the implementation of parseAndSummarize
.
Co-authored-by: Tim Jacomb <t.jacomb@kainos.com>
src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java
Outdated
Show resolved
Hide resolved
// to be a ' / '-joined string of the enclosing blocks names. JUnitChecksPublisher will handle defaults if | ||
// checksName ends up being empty or null | ||
String checksName = task.getChecksName() != null || pipelineTestDetails == null ? task.getChecksName() : | ||
StringUtils.join(new ReverseListIterator(pipelineTestDetails.getEnclosingBlockNames()), " / "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the spaces around the slash conventional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took my inspiration from
return StringUtils.join(new ReverseListIterator(getEnclosingFlowNodeNames()), " / ") + " / " + rawName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right…this is a display name for rendering in an HTML GUI, though, whereas a check name is in a somewhat different category because it is used as a key in the REST API, requested in branch protection settings, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using slashes in my own custom checks without issue; nothing seems to mind.
used as a key in the REST API
As in in Githubs REST API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using slashes in my own custom checks without issue
Yes of course, I am just asking if there is a convention for using strings that look more like display names (Tests / Branch / Stage
) or more like file paths or URIs (tests/branch/stage
).
As in in Githubs REST API?
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer display name. something like Tests / Unit
src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-checksName.html
Outdated
Show resolved
Hide resolved
src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
String checksName = task.getChecksName() != null || pipelineTestDetails == null ? task.getChecksName() : | ||
StringUtils.join(new ReverseListIterator(pipelineTestDetails.getEnclosingBlockNames()), " / "); | ||
// to be a ' / '-joined string of the enclosing blocks names. If all of that ends up being empty or null, | ||
// set a default of 'Test' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// set a default of 'Test' | |
// set a default of 'Tests' |
@After | ||
public void clearDetails() { | ||
InterceptingChecksPublisherFactory.publisher.details.clear(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming @Rule JenkinsRule
(rather than @ClassRule
), every test case gets its own Jenkins session, thus a new copy of every @TestExtension
, so this would be unnecessary if you just make publisher
an instance field rather than static
. To find the current InterceptingChecksPublisherFactory
instance, use ExtensionList.lookupSingleton
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, thanks! I figured there must be something like that.
// If we haven't been provided with a checks name, and we have pipeline test details, set the checks name | ||
// to be a ' / '-joined string of the enclosing blocks names. If all of that ends up being empty or null, | ||
// set a default of 'Tests' | ||
String checksName = task.getChecksName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes. For context I'm working mostly on python/js environments, where our stages are dedicated to test generation...
stage('JS Tests') {
sh 'yarn test'
junit 'js_tests.xml'
}
stage('Python Tests') {
sh 'pytest tests/'
junit 'python_tests.xml'
}
...as opposed to maven where tests are a bit more of a 'side effect' of the build
stage('Build') {
sh 'mvn install'
junit 'results.xml'
archiveArticfcats(...)
recordIssues(...)
// etc...
}
So we'd end up with JS Tests / Tests
etc. OTOH, I'm already setting a custom name (and will be using withChecks
when it's ready) so I think meeting the 'mvn' use case possibly makes more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the change locally,
+
+ private static final String DEFAULT_CHECKS_NAME = "Tests";
/**
* {@link FileSet} "includes" string, like "foo/bar/*.xml"
@@ -290,10 +294,12 @@ public class JUnitResultArchiver extends Recorder implements SimpleBuildStep, JU
// set a default of 'Tests'
String checksName = task.getChecksName();
if (checksName == null && pipelineTestDetails != null) {
- checksName = StringUtils.join(new ReverseListIterator(pipelineTestDetails.getEnclosingBlockNames()), " / ");
+ List<String> checksComponents = new ArrayList<>(pipelineTestDetails.getEnclosingBlockNames());
+ checksComponents.add(DEFAULT_CHECKS_NAME);
+ checksName = StringUtils.join(new ReverseListIterator(checksComponents), " / ");
}
if (Util.fixEmpty(checksName) == null) {
- checksName = "Tests";
+ checksName = DEFAULT_CHECKS_NAME;
}
Requires tests changes but that gives what I expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will get that done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry, you meant Tests
at the beginning...
a2e7710
to
c227039
Compare
c227039
to
db58881
Compare
#221 May be related, I didn’t do any complex testing in my setup |
This hopefully goes some way to address @jglick's concerns over the current behaviour (#210).
The default now (hopefully!) is that checks are published per junit invocation with a name derived from the enclosing blocks, unless otherwise overridden. This means that, assuming the idiom of one junit invocation per stage is followed, checks will not be overwritten losing data.