Open mikedld opened 1 year ago
Worked around second error (NullPointerException
) by applying the following patch (not sure how good it is, let me know if you want me to open a PR):
--- a/src/main/groovy/com/homeaway/devtools/jenkins/testing/JenkinsPipelineSpecification.groovy
+++ b/src/main/groovy/com/homeaway/devtools/jenkins/testing/JenkinsPipelineSpecification.groovy
@@ -606,6 +606,10 @@ public abstract class JenkinsPipelineSpecification extends Specification {
_objects.each { object ->
+ if( object.metaClass == null ) {
+ return;
+ }
+
final MetaMethod originalMethodMissing = object.metaClass.getMetaMethod("methodMissing", "string", new Object[0] )
object.metaClass.methodMissing = { String _name, _args ->
With the above patch applied, still fails with the first error (UnsupportedOperationException
), which could be worked around by bumping the cglib version from 3.2.7 to at least 3.2.9:
dependencies {
// ...
testImplementation 'cglib:cglib:3.2.9'
// ...
}
In Groovy every class has a metaClass.
But a class can obfuscate the call to metaClass if it has a method with this signature: get(String key)
Like org.apache.log4j.MDC
and org.slf4j.MDC
have. :wink:
The fix is not to check for a null, but to simply use object.getMetaClass()
instead of object.metaClass
.
I was able to workaround this issue by adding a Helper class to the test folder having a static initializer:
public class OutsmartJenkinsPipelineSpecification {
static {
def string = "metaClass"
string.metaClass.getMetaMethod { String it1, String it2, Object[] it3 -> }
string.metaClass.methodMissing = "methodMissing"
string.metaClass.propertyMissing = "propertyMissing"
org.slf4j.MDC.put("metaClass", string)
}
}
That adds a fake metaClass to the org.slf4j.MDC
class.
(Be aware if you are using MDC while running the tests.)
Expected Behavior
Test run with the most recent versions of
org.jenkins-ci.main:jenkins-core
package.Actual Behavior
When using
org.jenkins-ci.main:jenkins-core
version 2.356 and below, tests run as expected.When using
org.jenkins-ci.main:jenkins-core
version 2.357 up to 2.365, running tests produces an error for every test case:When using
org.jenkins-ci.main:jenkins-core
version 2.366 up to 2.395 (current latest), running tests produces an error for every test case:Steps to Reproduce
Current working dependencies (reduced from full set required for my project), bumping the version of
org.jenkins-ci.main:jenkins-core
leads to failures:Minimal failing test:
Additional Information