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

Assertions and predicates for the SpaceProvisionerConfig CRD #357

Merged
merged 14 commits into from
Jan 30, 2024

Conversation

metlos
Copy link
Contributor

@metlos metlos commented Jan 24, 2024

A generic way of declaring predicates that can be used both as assertions (through AssertThat function) and as criterions in e2e tests (in wait.For().FirstThat() introduced in the associated PR codeready-toolchain/toolchain-e2e#883).

Additionally, also as an example how to use it, this introduces support functions and predicates for SpaceProvisionerConfig unit tests in host-operator (codeready-toolchain/host-operator#963) and e2e tests in toolchain-e2e (codeready-toolchain/toolchain-e2e#883).

@metlos metlos changed the title A simple utility function for creating SpaceProvisionerConfigs in thetests. A simple utility function for creating SpaceProvisionerConfigs in the tests. Jan 24, 2024
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Merging #357 (948a4a6) into master (12ab087) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #357   +/-   ##
=======================================
  Coverage   76.42%   76.42%           
=======================================
  Files          43       43           
  Lines        1998     1998           
=======================================
  Hits         1527     1527           
  Misses        424      424           
  Partials       47       47           

@MatousJobanek
Copy link
Contributor

Let's add also the options to set the fields in the spec - what you've done in your e2e PR. But you can expand it by adding options to set "enabled" "thresholds" and other fields

@MatousJobanek
Copy link
Contributor

my point is to have functions that will help you to create the SPC objects:

spc := testSpc.NewSpaceProvisionerConfig("spc", test.HostOperatorNs, "cluster1", 
            testSpc.Enabled(), testSpc.WithReadyCondition(), testSpc.MaxNumberOfSpaces(1000), testSpc.MaxMemoryUtilizationPercent(85))

@MatousJobanek
Copy link
Contributor

just a side note: I would never ever ask you to move one simple function to toolchain-common 😄
I just saw the same patterns in your e2e and host-operator PRs and we will definitely need hepler functions that are mentioned above, that's why I proposed moving it to toolchain-common.

@MatousJobanek
Copy link
Contributor

but, if you feel that you won't use it in the next changes in both repos and you feel that it's not worth moving it here, then just say - it's fine ;-)

alexeykazakov and others added 5 commits January 24, 2024 09:26
be more flexible by using the option functions.
…tThat

function to work on any client.Object.

This enables the reuse of the predicates both in the helper functions for
unit tests (that can use the AssertThat function) as well as in end-to-end
tests (which can use wait.For().FirstThat()).

This enables us to reuse the same predicates across the whole testsuite
instead of having one set for unit tests and another set for the end-to-end
tests.
@metlos metlos changed the title A simple utility function for creating SpaceProvisionerConfigs in the tests. Assertions and predicates for the SpaceProvisionerConfig CRD Jan 25, 2024
@metlos
Copy link
Contributor Author

metlos commented Jan 26, 2024

@MatousJobanek the upload to codecov failed in this PR a couple of times in a row. Would you have an idea what might be causing this?

@alexeykazakov
Copy link
Collaborator

the upload to codecov failed in this PR a couple of times in a row. Would you have an idea what might be causing this?

Yes, it happens from time to time. Codecov uploads are not very reliable on the codecov side. We just have to keep re-running the failed job to get it through.

Copy link
Contributor

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

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

Nice and clean 🤩

Comment on lines +14 to +16
func (p predicate) Matches(obj *toolchainv1alpha1.SpaceProvisionerConfig) bool {
return p(obj)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, there is one disadvantage of using the same type predicate that returns just a boolean at both places - it's hard to understand why the unit test failed - there is no assertion message, that something was expected but the actual value is different

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, let's not try to solve all the problems of the universe in one PR - let's merge it as it is and let's see how this will evolve and is gonna be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is true... There are 2 ways of addressing it:

  1. Change AssertThat to accept msgAndArgs ...any and pass it to the inner assert.True so that the caller has some control over the output of the asserts.
  2. Change the Predicate.Matches to return (bool, string) where the second parameter could contain a description of why the predicate didn't match. This could then somehow be incorporated into AssertThat and wait.For().FirstThat().

I will update this PR with the former, but I would wait with the latter until we find we actually need it. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions

E Security Rating on New Code (required ≥ A)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

@metlos metlos merged commit fb41345 into codeready-toolchain:master Jan 30, 2024
9 of 10 checks passed
@metlos metlos deleted the KSPACE-28-spc-controller branch January 30, 2024 15:50
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.

3 participants