Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Test IncludeGenerated #381

Merged
merged 3 commits into from
Nov 25, 2021
Merged

Test IncludeGenerated #381

merged 3 commits into from
Nov 25, 2021

Conversation

genevieveluyt
Copy link
Contributor

@genevieveluyt genevieveluyt commented Nov 19, 2021

Description

Adds a test for #374

Additionally:

  • The service.yml ClusterIP was invalid ("The Service "test-service" is invalid: spec.clusterIP: Invalid value: "10.0.171.239": provided IP is not in the valid range. The range of valid IPs is 10.96.0.0/16")
  • Importing the test package in client_test.go caused a circular dependency so updated the package from k8sinternal to k8sinternal_test
Type of change
  • Bug fix 🐛
  • New feature ✨
  • This change requires a documentation update 📖
  • Breaking changes ⚠️
How Has This Been Tested?
  • Test A
  • Test B
Checklist:
  • I have 🎩 my changes (A 🎩 specifically includes pulling down changes, setting them up, and manually testing the changed features and potential side effects to make sure nothing is broken)
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The test coverage did not decrease
  • I have signed the appropriate Contributor License Agreement

@ghost ghost added the core label Nov 19, 2021
clusterIP: 10.96.0.1
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 service.yml ClusterIP was invalid ("The Service "test-service" is invalid: spec.clusterIP: Invalid value: "10.0.171.239": provided IP is not in the valid range. The range of valid IPs is 10.96.0.0/16").

This doesn't affect tests or anything. I just happened to try to kubectl apply the service into a kind cluster and it failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching that!

@@ -1,12 +1,15 @@
package k8sinternal
package k8sinternal_test

Choose a reason for hiding this comment

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

Is this the normal convention that the package test have a different name than the package itself? I've not done this before and I'm wondering if I should have been...

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember is something to do with blackbox/whitebox testing 💭. I think when we call this a different name, we would have to import k8sinternal in order to get access to the rest of the code.

Copy link
Contributor Author

@genevieveluyt genevieveluyt Nov 24, 2021

Choose a reason for hiding this comment

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

Exactly what Brian said! It depends what you want to test.

If you use the same package as the code you're testing (whitebox), you have access to the private methods in the package and can test those.

If you use the special _test package (normally Go won't let you have multiple package names in the same directory, so appending _test to the package is a special case), you can test your code as if you were a consumer of the package (blackbox).

In this case we're not testing any private methods so using the "test" package is kind of a cheat to get out of import cycle problems. Alternatively we could move the functions that cause the import cycle into a new package and import that from both k8sinternal and test.

Choose a reason for hiding this comment

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

TYVM for the explainer!

Copy link
Contributor

@rxbchen rxbchen 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!

@@ -1,12 +1,15 @@
package k8sinternal
package k8sinternal_test
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember is something to do with blackbox/whitebox testing 💭. I think when we call this a different name, we would have to import k8sinternal in order to get access to the rest of the code.

clusterIP: 10.96.0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching that!

@genevieveluyt genevieveluyt merged commit 55ef5fa into main Nov 25, 2021
@genevieveluyt genevieveluyt deleted the include-generated-test branch November 25, 2021 15:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants