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

feat: bootstrapped junit-jupiter Kubernetes module #4117

Merged
merged 3 commits into from
May 5, 2022

Conversation

manusa
Copy link
Member

@manusa manusa commented May 4, 2022

Description

Follow-up on #4054 / #4008

Exposes the JUnit 5 extension in a new kubernetes-junit-jupiter artifact.

As described in #4054, this module would allow you to configure your tests like:

@KubernetesTest
@LoadKubernetesManifests("/test-data.yml")
@RequireK8sSupport(io.fabric8.knative.serving.v1.Service.class) // Optionally require support for a resource  (test env should be reliable)
@RequireK8sVersionAtLeast(majorVersion = 1, minorVersion = 16) // Optionally require a specific K8s version
class MyTest {
  KubernetesClient client;
}

Maybe we can add configuration options in the future to the @KubernetesTest annotation:

  • Disable namespace creation
  • Use of specific named namespace
  • ...

/cc @andreaTP

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

@manusa manusa added the wip label May 4, 2022
@manusa manusa force-pushed the feat/junit-jupiter-extension branch 4 times, most recently from d29c454 to b331cf1 Compare May 4, 2022 13:45
@manusa manusa changed the title wip: bootstrapped junit-jupiter Kubernetes module feat: bootstrapped junit-jupiter Kubernetes module May 4, 2022
@manusa manusa removed the wip label May 4, 2022
@manusa manusa force-pushed the feat/junit-jupiter-extension branch from b331cf1 to c6694f4 Compare May 4, 2022 13:48
@manusa manusa marked this pull request as ready for review May 4, 2022 13:48
manusa added 3 commits May 4, 2022 16:01
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa force-pushed the feat/junit-jupiter-extension branch from c6694f4 to f0f34ba Compare May 4, 2022 14:01
@sonarcloud
Copy link

sonarcloud bot commented May 4, 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 41 Code Smells

48.6% 48.6% Coverage
0.0% 0.0% Duplication

Copy link
Member

@andreaTP andreaTP left a comment

Choose a reason for hiding this comment

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

Amazing, thanks!

Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@metacosm metacosm 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! Maybe worth looking into adding support for this in Quarkus in a way similar to the @WithKubernetesTestServer annotation?

@manusa
Copy link
Member Author

manusa commented May 5, 2022

Looks good! Maybe worth looking into adding support for this in Quarkus in a way similar to the @WithKubernetesTestServer annotation?

I think for Quarkus we need to provide a specific implementation considering a use case where this client would be injected into the production code.

Anyway, for me the first step is releasing the snapshot and see what kind of usages our users make of this. In my case, I will be reusing part of this features in our jkube-integration-tests repository.

Further refinements and enhancements might include adding configuration options to the @KubernetesTest annotation:

public @interface KubernetesTest {
  /**
   * Should a namespace be created for the test and the client instance configured to use it?
   */
  boolean createNamespace() default true;
  /**
   * Fixed namespace to use instad of the UUID generated default.
   */
  String namespace();
}

But following the YAGNI principle, I think that some feedback might be better first.

Also note that the JUnit extensions should be composable (check the LoadKubernetesManifestsExtension implementation and LoadKubernetesManifests annotation). I'm commenting this especially for the JOSDK specific extension that could very well reuse the namespace creation part, and then do its own thing.

@ExtendWith({ KubernetesNamespacedTestExtension.class, OperatorExtension.class })
public @interface OperatorSdkTest {
// ....
}

@manusa
Copy link
Member Author

manusa commented May 5, 2022

I'm merging now so that it makes it to tonight's snapshot release

@manusa manusa merged commit 25eb587 into fabric8io:master May 5, 2022
@manusa manusa deleted the feat/junit-jupiter-extension branch May 5, 2022 15:22
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.

None yet

5 participants