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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

#917 - Add test-harness module + change json schema test API to return list of errors #1215

Merged
merged 7 commits into from
Dec 10, 2019

Conversation

timja
Copy link
Member

@timja timja commented Dec 3, 2019

Note: the json schema test API has never been released.

Previously errors in tests just said Assertion failed, with this change a list of exact errors are returned and the error looks like:

assertThat(validateSchema(convertYamlFileToJson(this, "invalidSchemaConfig.yml")),
            empty());
java.lang.AssertionError: 
Expected: an empty collection
     but: <[#/jenkins/numExecutors: expected type: Number, found: String]>

This can then be asserted on to check expected errors, or empty

The test harness module had to be introduced so that the json schema dependency would get included, it seems test-jars don't include dependencies. All tests that depended on classes from the misc test package had to be moved to the test-harness module so that there was no cyclic dependency

Your checklist for this pull request

馃毃 Please review the guidelines for contributing to this repository.

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@timja
Copy link
Member Author

timja commented Dec 3, 2019

I extracted this from #1027 as we may want to do a release for #1214 and the test framework is on master, I would rather not release an API that isn't as good as it could be

jetersen
jetersen previously approved these changes Dec 3, 2019
Copy link
Member

@jetersen jetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

try {
returnSchema().validate(jsonSubject);
} catch (ValidationException e) {
return e.getAllMessages();
} catch (Exception ie) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still required, would reducing them to one block make sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? this is the whole point of the change, the validation messages are now returned as a list.

@timja
Copy link
Member Author

timja commented Dec 3, 2019

Hmm

Caused by: java.lang.ClassNotFoundException: org.everit.json.schema.ValidationException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 22 more

@timja
Copy link
Member Author

timja commented Dec 4, 2019

Not having a fun time with this, the test jar doesn't want to include the dependency on the json schema dependency.

If I add the dependency to the integrations module that works but not good enough for other consumers who need it

@timja
Copy link
Member Author

timja commented Dec 4, 2019

If anyone has time to look at this it would be much appreciated

@jetersen
Copy link
Member

jetersen commented Dec 5, 2019

I'll have a look after Jenkins world 馃槄

@timja
Copy link
Member Author

timja commented Dec 5, 2019

I'll have a look after Jenkins world 馃槄

I tried fiddling with the dependency set but didn't manage to make it work

@timja
Copy link
Member Author

timja commented Dec 7, 2019

https://maven.apache.org/plugins-archives/maven-jar-plugin-2.6/examples/create-test-jar.html

In order to let Maven resolve all test-scoped transitive dependencies you should create a separate project.

@jetersen
Copy link
Member

jetersen commented Dec 7, 2019

Ya would be great if we could generate the test jar from it's own POM xml

@timja
Copy link
Member Author

timja commented Dec 7, 2019

I tried moving it to it's own module, but got cyclic dependency issues :(

@jetersen
Copy link
Member

jetersen commented Dec 7, 2019

Depend on the test module with an exclude to avoid the cyclic dependency?

@timja
Copy link
Member Author

timja commented Dec 7, 2019

Depend on the test module with an exclude to avoid the cyclic dependency?

Didn't work, I'm moving all the tests that rely on the rule / Util to the test module and will see how that looks

@timja
Copy link
Member Author

timja commented Dec 7, 2019

Pushed, seemed to be working locally, although I didn't wait for a full run.

@timja timja force-pushed the change-json-schema-test-api branch from c76b703 to cd01391 Compare December 7, 2019 17:11
@jetersen
Copy link
Member

jetersen commented Dec 7, 2019

codacy has some opinion :)

@timja
Copy link
Member Author

timja commented Dec 7, 2019

codacy has some opinion :)

on ancient code I haven't touched (but moved in src from test) 馃槈

@jetersen
Copy link
Member

jetersen commented Dec 7, 2019

Not true have a look at the changes: cd01391

@timja
Copy link
Member Author

timja commented Dec 7, 2019

Not true have a look at the changes: cd01391

wtf =/, IDE went mad I guess...

@timja timja requested a review from sladyn98 December 7, 2019 17:56
@timja timja changed the title Change json schema test API to return list of errors Add test-harness module + change json schema test API to return list of errors Dec 7, 2019
Copy link
Member

@jetersen jetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃グ Looks good to me! 馃惓

I wanted to split it earlier, thanks for your hard work @timja 馃挭

@@ -212,10 +212,9 @@ Add the Configuration as Code plugin as a test dependency in your pom.xml:
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<groupId>io.jenkins.configuration-as-code</groupId>
Copy link
Member

@jetersen jetersen Dec 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be documented in the release notes so when dependabot does the PR it is very transparent that this is the change we did (since we have removed the test jar under classifier tests)

@timja
Copy link
Member Author

timja commented Dec 7, 2019

@oleg-nenashev
Copy link
Member

oleg-nenashev commented Dec 7, 2019

Note that it will reduce efficiency of PCT. FYI @batmat @varyvol @alecharp

@sladyn98
Copy link
Contributor

sladyn98 commented Dec 7, 2019

Looks like the dependencies caused a bit of a problem.List of errors would give us more information while debugging. LGTM. Thanks @timja

@timja
Copy link
Member Author

timja commented Dec 7, 2019

Note that it will reduce efficiency of PCT. FYI @BatMar @varyvol @alecharp

How so? I assume it's because plugins won't be using the new dependency and might fail on new jcasc versions.

@timja
Copy link
Member Author

timja commented Dec 7, 2019

I don't really understand why it takes 2hr 30 to build this on jenkins CI and 11 minutes on GitHub actions 馃槧

@timja
Copy link
Member Author

timja commented Dec 9, 2019

hosting permissions have been updated to allow publishing this module
@oleg-nenashev are you happy with this change?

@timja timja added chore a PR that adds to maintenance - used by Release Drafter breaking A PR that is a breaking change - used by Release Drafter labels Dec 9, 2019
@timja
Copy link
Member Author

timja commented Dec 10, 2019

Will merge later today if no objections.
cc @oleg-nenashev

@oleg-nenashev
Copy link
Member

How so? I assume it's because plugins won't be using the new dependency and might fail on new jcasc versions.

Plugin Compatibility Tester invokes tests only in the plugin module. This change moves some of the tests to a different location. IIRC there should have been a bug created for it after JENKINS-58069, but I cannot find it. CC @varyvol

Apart from that, no objection w.r.t the PR itself

@timja timja merged commit 6cc682c into jenkinsci:master Dec 10, 2019
@timja timja deleted the change-json-schema-test-api branch December 10, 2019 09:14
@oleg-nenashev
Copy link
Member

Probably I should have been more explicit. My preference was to wait a bit more to gather feedback from interested parties. But 馃し鈥嶁檪 since it was merged, we can revisit it if there is any feedback

@oleg-nenashev
Copy link
Member

Fixes #917

@oleg-nenashev oleg-nenashev changed the title Add test-harness module + change json schema test API to return list of errors #917 - Add test-harness module + change json schema test API to return list of errors Dec 10, 2019
timja pushed a commit that referenced this pull request Jan 11, 2020
Co-authored-by: Oleg Nenashev <o.v.nenashev@gmail.com>
@jglick
Copy link
Member

jglick commented Jan 13, 2020

plugins won't be using the new dependency and might fail on new jcasc versions

Yes, this is a problem. jenkinsci/bom#164

LinuxSuRen pushed a commit to alauda/configuration-as-code-plugin that referenced this pull request Feb 21, 2020
* Add support to backup and restore automatically

* Fix the potential output resource leak

* Add configs about deploy into alauda update-center

* Set alauda as the main branch

* Add sonarqube properties file

* Fix the potentital issues

* Add a merge strategy extension point for the YAML config (#1)

* Add YAML merge strategy

* Add a new merge strategy

* Remove override merge strategy

* Clean the unused code lines

* Clean the unused imports

* Add test cases for merge strategy

* Fix the wrong test cases

* Take merge strategy name everytime

* Give the default strategy a more readable name

* Validate top README with the Integrations tests (jenkinsci#1229)

* Fix the compilation error caused by merge strategy

* Fix issues which found by spotbugs

* Remove unused imports

* Move profiles from pom.xml into settings file

* Remove empty line

* rename the shared-library

* Schema Generation for nested yml configurations (jenkinsci#1027)

* Trying to diagnose some flaky tests (jenkinsci#1243)

* Update ci to include code coverage after jenkinsci#1215 (jenkinsci#1241)

Co-authored-by: Oleg Nenashev <o.v.nenashev@gmail.com>

* Checkstyle ignore release.properties (jenkinsci#1245)

* [maven-release-plugin] prepare release configuration-as-code-1.35

* [maven-release-plugin] prepare for next development iteration

* Bump jackson.version from 2.10.1 to 2.10.2

Bumps `jackson.version` from 2.10.1 to 2.10.2.

Updates `jackson-databind` from 2.10.1 to 2.10.2
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)

Updates `jackson-dataformat-yaml` from 2.10.1 to 2.10.2
- [Release notes](https://github.com/FasterXML/jackson-dataformats-text/releases)
- [Commits](FasterXML/jackson-dataformats-text@jackson-dataformats-text-2.10.1...jackson-dataformats-text-2.10.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Correct spelling of hpi.pluginChangelogUrl tag (jenkinsci#1248)

* Automatically request code reviews from all JCasC plugin developers (jenkinsci#1249)

* [Security] Bump checkstyle from 8.26 to 8.29

Bumps [checkstyle](https://github.com/checkstyle/checkstyle) from 8.26 to 8.29. **This update includes a security fix.**
- [Release notes](https://github.com/checkstyle/checkstyle/releases)
- [Commits](checkstyle/checkstyle@checkstyle-8.26...checkstyle-8.29)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* It has been renamed to `master.componentName` (jenkinsci#1256)

Co-authored-by: Tim Jacomb <t.jacomb@kainos.com>

* Fix the version specification for Jenkins 2.199 (jenkinsci#1268)

* Added example for credentials certificate (jenkinsci#1270)

* Use the latest shared-library branch

* Update test to match latest plugin version (jenkinsci#1273)

* Update the integration test for active-directory (jenkinsci#1274)

* Add integration test for pipeline-model-definition (jenkinsci#1276)

* Fix the error when no casc user dir (#5)

* Add missing of mode in the context

* Use the same version of jackson-core

* Use the same version of jackson-core

* Use 2.8 as the major version

* Fix the wrong parent id for the plugin releasing

* Move the user config into a backup dir

* Run build under java pod

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
Co-authored-by: Sladyn <sladynnunes98@gmail.com>
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
Co-authored-by: Joseph Petersen <josephp90@gmail.com>
Co-authored-by: Oleg Nenashev <o.v.nenashev@gmail.com>
Co-authored-by: Tim Jacomb <t.jacomb@kainos.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
Co-authored-by: Jhon Mike <jhon.msdev@gmail.com>
Co-authored-by: Dawid Gos艂awski <50369002+dg-nvm@users.noreply.github.com>
Co-authored-by: choeffer <33625292+choeffer@users.noreply.github.com>
Co-authored-by: Francisco Fern谩ndez <31063239+fcojfernandez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A PR that is a breaking change - used by Release Drafter chore a PR that adds to maintenance - used by Release Drafter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants