| 18 | var _ ReadinessChecker = ReadinessCheckerFn(IsReady) |
| 19 | |
| 20 | func TestIsReady(t *testing.T) { |
| 21 | type args struct { |
| 22 | ctx context.Context |
| 23 | o ConditionedObject |
| 24 | rc []v1beta1.ReadinessCheck |
| 25 | } |
| 26 | type want struct { |
| 27 | ready bool |
| 28 | err error |
| 29 | } |
| 30 | cases := map[string]struct { |
| 31 | reason string |
| 32 | args |
| 33 | want |
| 34 | }{ |
| 35 | "NoCustomCheckReady": { |
| 36 | reason: "If no custom check is given, Ready condition should be used", |
| 37 | args: args{ |
| 38 | o: composed.New(composed.WithConditions(xpv1.Available())), |
| 39 | }, |
| 40 | want: want{ |
| 41 | ready: true, |
| 42 | }, |
| 43 | }, |
| 44 | "NoCustomCheckNotReady": { |
| 45 | reason: "If no custom check is given, Ready condition should be used", |
| 46 | args: args{ |
| 47 | o: composed.New(composed.WithConditions(xpv1.Unavailable())), |
| 48 | }, |
| 49 | want: want{ |
| 50 | ready: false, |
| 51 | }, |
| 52 | }, |
| 53 | "MatchConditionReady": { |
| 54 | reason: "If a match condition is explicitly specified it should be used", |
| 55 | args: args{ |
| 56 | o: composed.New(composed.WithConditions(xpv1.Available())), |
| 57 | rc: []v1beta1.ReadinessCheck{{ |
| 58 | Type: v1beta1.ReadinessCheckTypeMatchCondition, |
| 59 | MatchCondition: &v1beta1.MatchConditionReadinessCheck{ |
| 60 | Type: xpv1.TypeReady, |
| 61 | Status: corev1.ConditionTrue, |
| 62 | }, |
| 63 | }}, |
| 64 | }, |
| 65 | want: want{ |
| 66 | ready: true, |
| 67 | }, |
| 68 | }, |
| 69 | "MatchConditionNotReady": { |
| 70 | reason: "If a match condition is explicitly specified it should be used", |
| 71 | args: args{ |
| 72 | o: composed.New(composed.WithConditions(xpv1.Unavailable())), |
| 73 | rc: []v1beta1.ReadinessCheck{{ |
| 74 | Type: v1beta1.ReadinessCheckTypeMatchCondition, |
| 75 | MatchCondition: &v1beta1.MatchConditionReadinessCheck{ |
| 76 | Type: xpv1.TypeReady, |
| 77 | Status: corev1.ConditionTrue, |