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

Add tests #14

Merged
merged 3 commits into from Jul 20, 2022
Merged

Add tests #14

merged 3 commits into from Jul 20, 2022

Conversation

vihaanthora
Copy link
Contributor

@vihaanthora vihaanthora commented Jul 12, 2022

This PR adds two tests that test the HyperLocalPluginManager.java class. The resources/git-plugin/plugins folder contains the jpis of git-plugin. PipelineStepExtractor and QuasiDescriptor are added to facilitate testing. They are the same as the ones in pipeline-steps-doc-generator, except PipelineStepExtractor has been reduced to the functions required for testing. In HyperLocalPluginManager.java, the access modifier has been changed to public in L531 (as the method is required by pipeline-steps-doc-generator) and the unnecessary error stack trace removed in L539.

All other changes are formatting-related, to make the indentation and spacing uniform.

Once this PR gets merged, the artifact will be ready to use in pipeline-steps-doc-generator.

cc: @kwhetstone @arpoch @jmMeessen

@vihaanthora vihaanthora marked this pull request as draft July 12, 2022 16:11
Copy link

@kwhetstone kwhetstone left a comment

Choose a reason for hiding this comment

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

Vihaan and I talked about the test cases in our meeting. Looking forward to releasing the first version of the incrementals!

@@ -19,7 +19,8 @@
import jenkins.model.Jenkins;

/**
* A mocked way to get at {@link ExtensionList}s. In {@code hudson} package due to protected access in {@link ExtensionList}.
* A mocked way to get at {@link ExtensionList}s. In {@code hudson} package due

Choose a reason for hiding this comment

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

Love that you added some comments to the class. It's always a good thing to do in order to help people understand what's happening in pieces of code.

jenkinsHolderField.set(null, mockJenkinsHolder);

InitStrategy initStrategy = new InitStrategy();
executeReactor(initStrategy, pluginManager.diagramPlugins(initStrategy));

Choose a reason for hiding this comment

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

You are all good right up until here, then at this point you'll want to return the pluginManager. Then, we'll use the pluginManager in the test itself.

public static void init() {
steps = pse.findSteps(pluginDir);
for (String plugin : steps.keySet()) {
LOG.info("processing " + plugin);

Choose a reason for hiding this comment

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

We don't want to keep the logs in the tests.


@Test
public void areTotalStepsFortySeven() {
assertEquals(47, count);

Choose a reason for hiding this comment

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

This is a good place to return the pluginManger and query the plugin manager. You can specifically use the pluginManager methods to look for the git plugin step.

/**
* Process and find all the Pipeline steps definied in Jenkins plugins.
*/
public class PipelineStepExtractor {

Choose a reason for hiding this comment

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

I do also want to point out that having a separate class for setting up the HyperLocalPluginManager and running the reactor. This is a great idea!

@vihaanthora
Copy link
Contributor Author

vihaanthora commented Jul 13, 2022

@kwhetstone I added a commit now, I have tried to address everything that we discussed yesterday. The only thing that is perhaps missing now is adding tests for diagramPlugins. In case we don't require it now, I will mark this PR as ready for review.

@@ -43,6 +43,11 @@
<artifactId>mockito-core</artifactId>
<version>4.6.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got rid of the mockito error messages by adding an extra dependency as mentioned in the GitHub discussion here.

Copy link

@kwhetstone kwhetstone left a comment

Choose a reason for hiding this comment

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

This is great test refactoring! It's great to have the test running to make sure you've covered the green path for PluginManager.

@@ -305,7 +321,8 @@ protected Enumeration<URL> findResources(String name) throws IOException {
List<URL> resources = new ArrayList<>();
if (FAST_LOOKUP) {
for (PluginWrapper p : activePlugins) {
resources.addAll(Collections.list(ClassLoaderReflectionToolkit._findResources(p.classLoader, name)));
resources

Choose a reason for hiding this comment

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

I'm not the largest fan of this lint change since it seems less clear to me.

@@ -400,21 +415,23 @@ public <T> List<T> findComponents(Class<T> type) {
}

/**
* This is pretty much a copy of the final ExtensionFinder.Sezpoz class from 1.651 fitted
* This is pretty much a copy of the final ExtensionFinder.Sezpoz class from
* 1.651 fitted

Choose a reason for hiding this comment

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

Note: something we might need to do in this repo is do a refresh on Sezpoz. A good ticket for this repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, would like to know more about this in the office hours.

@@ -515,20 +528,20 @@ public void scout(ClassLoader cl) {
* @param d descriptor
* @return name of the plugin this class belongs to, or "core" if not found
*/
protected String getPluginNameForDescriptor(Descriptor<?> d) {
public String getPluginNameForDescriptor(Descriptor<?> d) {

Choose a reason for hiding this comment

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

I like this public as well especially since this is now a public utility.

} catch (Exception ex) {
LOG.log(Level.SEVERE, "Plugin Manager failed to initialize", ex);
}
return pluginManager;

Choose a reason for hiding this comment

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

Perfect!

* If non-null, this can be consulted for ignoring some tasks. Only
* used during the initialization of Jenkins.
*/
private void executeReactor(final InitStrategy is, TaskBuilder... builders)

Choose a reason for hiding this comment

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

Right, this is pulled directly from the internals of Jenkins.

}

@Test
public void TotalStepsShouldBeFortySeven() {

Choose a reason for hiding this comment

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

Cool. You can also make a comment for this method showing it's testing that the pluginStrategy loads itself correctly.

@vihaanthora vihaanthora marked this pull request as ready for review July 19, 2022 13:58
@vihaanthora
Copy link
Contributor Author

I have made the required changes and added some comments.

@jmMeessen jmMeessen merged commit 4891407 into jenkins-infra:master Jul 20, 2022
@vihaanthora vihaanthora deleted the tests branch July 25, 2022 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants