Skip to content

fix #3912: simplifying extension mocking #3913

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

Merged
merged 8 commits into from
Mar 8, 2022

Conversation

shawkins
Copy link
Contributor

@shawkins shawkins commented Mar 2, 2022

Description

fix for #3912 - a general approach to mock support. For now everything that a user could be using was deprecated, rather
than removed

As mentioned on the other comment, I did not try to reduce the duplication between the extension classes because the other implementation should go away in a subsequent release.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@shawkins
Copy link
Contributor Author

shawkins commented Mar 2, 2022

I still need to update the extension test poms to no longer reference the specific mock dependency - done now.

for now everything that a user could be using was deprecated, rather
than removed
@shawkins shawkins linked an issue Mar 2, 2022 that may be closed by this pull request
Copy link
Member

@iocanel iocanel left a comment

Choose a reason for hiding this comment

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

Looks amazing!

@shawkins
Copy link
Contributor Author

shawkins commented Mar 3, 2022

Do we want to go one step further and add this functionality into the existing EnableKubernetesMockClient rather than introducing the new EnableKubernetesMock?

@manusa
Copy link
Member

manusa commented Mar 4, 2022

Do we want to go one step further and add this functionality into the existing EnableKubernetesMockClient rather than introducing the new EnableKubernetesMock?

I'm missing the point of the EnableKubernetesMock annotation. IMHO our end goal should be to provide a single JUnit5 annotation and JUnit4 rule and prescribe those. We should probably keep the old annotation+rule (if renamed) for compatibility reasons.

So in this case (and if my assumptions are correct), we should keep both annotations, but provide only a single extension that covers everything.

? new KubernetesMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https())
: new KubernetesMockServer(a.https());
mock.init();
client = new DefaultKubernetesClient(mock.getMockConfiguration());
Copy link
Member

Choose a reason for hiding this comment

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

Why is an explicit client instantiation needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we need the functionality that is below the KubernetesClient, see the next call. We could adapt(BaseClient.class) instead if you want to avoid what will be a deprecated call for a while.

Copy link
Member

Choose a reason for hiding this comment

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

Then maybe we should change the return type of KubernetesMockServer#createClient to BaseClient. Then change that in the future if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately createClient effectively became a user facing method and should not expose -client classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implies that usage of the ExternalResource won't work correctly in adapting scenarios. We need KubernetesMockServerExtension and KubenetesServer to share the same KubernetesMockServer and client creation logic for that.

@shawkins
Copy link
Contributor Author

shawkins commented Mar 4, 2022

So in this case (and if my assumptions are correct), we should keep both annotations, but provide only a single extension that covers everything.

I've updated the pr with using just a single annotation / extension. The only difference is that by default all Clients seen in the test class will be created the same way as a KubernetesClient. If that seems like an acceptable change, I'd just reuse the existing annotation. The purpose of the extensions class may shift depending on the resolution of #3922

@shawkins
Copy link
Contributor Author

shawkins commented Mar 4, 2022

@manusa the next commit addressed your concerns and puts everything using the same mechanisms.

Comment on lines 148 to 165
* ---
* apiVersion: "networking.istio.io/v1beta1"
* kind: "VirtualService"
* metadata:
* annotations: {}
* finalizers: []
* labels: {}
* name: "details"
* ownerReferences: []
* spec:
* hosts:
* - "details"
* http:
* - route:
* - destination:
* host: "details"
* subset: "v1"
*/
Copy link
Member

Choose a reason for hiding this comment

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

Indentation was broken here by spotless 😭
Need to wrap with <pre>{@code ... }</pre>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The config has

<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>

On something like this, I'd opt for just removing from the file - we generally don't have comments with the raw yaml anywhere else.

Copy link
Member

@manusa manusa Mar 7, 2022

Choose a reason for hiding this comment

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

I understand that <pre> enclosed Javadoc should not be altered.

Anyway, just remove it then. One way or the other, we shouldn't have invalid YAML.

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've updated this to use formatter:off / on

@manusa manusa mentioned this pull request Mar 7, 2022
11 tasks
shawkins added 2 commits March 7, 2022 12:06
extension-api

# Conflicts:
#	extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotClassTest.java
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 7, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 27 Code Smells

58.0% 58.0% Coverage
0.0% 0.0% Duplication

@manusa manusa added this to the 6.0.0 milestone Mar 8, 2022
@manusa manusa merged commit 850044a into fabric8io:master Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify extension mocking
4 participants