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 utility functions to support tests on SpaceProvisionerConfig.Status.ConsumedCapacity #434

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

metlos
Copy link
Contributor

@metlos metlos commented Nov 19, 2024

This just adds a couple of utility functions and predicates to be used by the tests on the new SpaceProvisionerConfig.Status.ConsumedCapacity. The functions will be used in code in the host operator and e2e tests in the upcoming PRs.

Copy link

sonarcloud bot commented Nov 19, 2024

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.23%. Comparing base (a6a8525) to head (266b4a1).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #434   +/-   ##
=======================================
  Coverage   78.23%   78.23%           
=======================================
  Files          49       49           
  Lines        2444     2444           
=======================================
  Hits         1912     1912           
  Misses        478      478           
  Partials       54       54           

Comment on lines +35 to +48
cond, found := condition.FindConditionByType(spc.Status.Conditions, toolchainv1alpha1.ConditionReady)
if !found {
return false
}

func (*ready) FixToMatch(spc *toolchainv1alpha1.SpaceProvisionerConfig) *toolchainv1alpha1.SpaceProvisionerConfig {
spc.Status.Conditions, _ = condition.AddOrUpdateStatusConditions(spc.Status.Conditions, toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
Reason: toolchainv1alpha1.SpaceProvisionerConfigValidReason,
})
return spc
}
if cond.Status != r.expectedStatus {
return false
}

func Ready() assertions.Predicate[*toolchainv1alpha1.SpaceProvisionerConfig] {
return &ready{}
}
if r.expectedReason != nil && cond.Reason != *r.expectedReason {
return false
}

func (*notReady) Matches(spc *toolchainv1alpha1.SpaceProvisionerConfig) bool {
return condition.IsFalse(spc.Status.Conditions, toolchainv1alpha1.ConditionReady)
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using ConditionsMatch or ContainsCondition from the test package

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 main reason is that this struct is reused in a couple of predicate functions, e.g. func NotReady() returns a predictate that tests only for the readiness status of the ready condition regardless of the reason, which is not expressible using ConditionsMatch or ContainsCondition.

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.

please, consider using the already existing functions related to conditions available in the repo #434 (comment)

@metlos metlos merged commit e2e3546 into codeready-toolchain:master Nov 28, 2024
9 checks passed
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.

2 participants