-
Notifications
You must be signed in to change notification settings - Fork 78
feat: create new ttr for tiertemplate updates #1102
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
Changes from 11 commits
a782f5e
2320516
9f70a26
0b6523f
033039b
ab66034
7735de5
8935625
e1c758d
0a6175e
37a322b
e3a9bcc
124a1c0
488ef7b
719c2a1
03473b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -994,6 +994,100 @@ func (a *HostAwaitility) WaitForTierTemplate(t *testing.T, name string) (*toolch | |
| return tierTemplate, err | ||
| } | ||
|
|
||
| // TierTemplateRevisionWaitCriterion a struct to compare with an expected TierTemplateRevision | ||
| type TierTemplateRevisionWaitCriterion struct { | ||
| Match func([]toolchainv1alpha1.TierTemplateRevision) bool | ||
| Diff func([]toolchainv1alpha1.TierTemplateRevision) string | ||
| } | ||
|
|
||
| func matchTierTemplateRevisionWaitCriterion(actual []toolchainv1alpha1.TierTemplateRevision, criteria ...TierTemplateRevisionWaitCriterion) bool { | ||
| for _, c := range criteria { | ||
| // if at least one criteria does not match, keep waiting | ||
| if !c.Match(actual) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| func (a *HostAwaitility) printTierTemplateRevisionWaitCriterionDiffs(t *testing.T, actual []toolchainv1alpha1.TierTemplateRevision, tierName string, criteria ...TierTemplateRevisionWaitCriterion) { | ||
| buf := &strings.Builder{} | ||
| if len(actual) == 0 { | ||
| buf.WriteString("no ttrs found\n") | ||
| } else { | ||
| buf.WriteString("failed to find ttrs with matching criteria:\n") | ||
| buf.WriteString("actual:\n") | ||
| for _, obj := range actual { | ||
| y, _ := StringifyObject(&obj) // nolint:gosec | ||
| buf.Write(y) | ||
| } | ||
| buf.WriteString("\n----\n") | ||
| buf.WriteString("diffs:\n") | ||
| for _, c := range criteria { | ||
| if !c.Match(actual) { | ||
| buf.WriteString(c.Diff(actual)) | ||
| buf.WriteString("\n") | ||
| } | ||
| } | ||
| } | ||
| opts := client.MatchingLabels(map[string]string{ | ||
| toolchainv1alpha1.TierLabelKey: tierName, | ||
| }) | ||
| // include also all TierTemplateRevisions for the given tier, to help troubleshooting | ||
| a.listAndPrint(t, "TierTemplateRevisions", a.Namespace, &toolchainv1alpha1.TierTemplateRevisionList{}, opts) | ||
| // include also all TierTemplate for the given tiertemplate revisions, to help troubleshooting | ||
| for _, ttr := range actual { | ||
| a.GetAndPrint(t, "TierTemplate", a.Namespace, ttr.GetLabels()[toolchainv1alpha1.TemplateRefLabelKey], &toolchainv1alpha1.TierTemplate{}) | ||
| } | ||
|
|
||
| t.Log(buf.String()) | ||
| } | ||
|
|
||
| // GreaterOrEqual checks if the number of TTRs is greater or equal than the expected one | ||
| func GreaterOrEqual(count int) TierTemplateRevisionWaitCriterion { | ||
| return TierTemplateRevisionWaitCriterion{ | ||
| Match: func(actual []toolchainv1alpha1.TierTemplateRevision) bool { | ||
| return len(actual) >= count | ||
| }, | ||
| Diff: func(actual []toolchainv1alpha1.TierTemplateRevision) string { | ||
| return fmt.Sprintf("number of ttrs %d is not greater or equal than %d \n", len(actual), count) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // LessOrEqual checks if the number of TTRs is less or equal than the expected one | ||
| func LessOrEqual(count int) TierTemplateRevisionWaitCriterion { | ||
| return TierTemplateRevisionWaitCriterion{ | ||
| Match: func(actual []toolchainv1alpha1.TierTemplateRevision) bool { | ||
| return len(actual) <= count | ||
| }, | ||
| Diff: func(actual []toolchainv1alpha1.TierTemplateRevision) string { | ||
| return fmt.Sprintf("number of ttrs %d is not less or equal than %d \n", len(actual), count) | ||
| }, | ||
| } | ||
| } | ||
|
Comment on lines
+1046
to
+1068
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, these could be generic functions available as part of the new
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, not huge expert and fan of generic code, but I agree it might make sense. Actually there's also a lot of margin for improvement in the assertions of the TTRs as well. We can do those later if that makes sense.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned during the sync call, I found a way we can use the standard assertion functions |
||
|
|
||
| func (a *HostAwaitility) WaitForTTRs(t *testing.T, tierName string, criteria ...TierTemplateRevisionWaitCriterion) ([]toolchainv1alpha1.TierTemplateRevision, error) { | ||
| t.Logf("waiting for ttrs to match criteria for tier '%s'", tierName) | ||
| var ttrs []toolchainv1alpha1.TierTemplateRevision | ||
| err := wait.PollUntilContextTimeout(context.TODO(), a.RetryInterval, a.Timeout, true, func(ctx context.Context) (done bool, err error) { | ||
| objs := &toolchainv1alpha1.TierTemplateRevisionList{} | ||
| if err := a.Client.List(ctx, objs, client.InNamespace(a.Namespace), client.MatchingLabels{toolchainv1alpha1.TierLabelKey: tierName}); err != nil { | ||
| return false, err | ||
| } | ||
| if len(objs.Items) == 0 { | ||
| return false, nil | ||
| } | ||
| ttrs = objs.Items | ||
| return matchTierTemplateRevisionWaitCriterion(ttrs, criteria...), nil | ||
| }) | ||
| // no match found, print the diffs | ||
| if err != nil { | ||
| a.printTierTemplateRevisionWaitCriterionDiffs(t, ttrs, tierName, criteria...) | ||
| } | ||
| return ttrs, err | ||
| } | ||
|
|
||
| // NSTemplateTierWaitCriterion a struct to compare with an expected NSTemplateTier | ||
| type NSTemplateTierWaitCriterion struct { | ||
| Match func(*toolchainv1alpha1.NSTemplateTier) bool | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.