Skip to content

Commit

Permalink
Add unit tests for porch.condition (#433)
Browse files Browse the repository at this point in the history
Add unit tests to condition module.
94%

---------

Signed-off-by: efiacor <fiachra.corcoran@est.tech>
  • Loading branch information
efiacor authored Nov 13, 2023
1 parent c1d7bd4 commit 9ec4452
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
11 changes: 0 additions & 11 deletions controllers/pkg/porch/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,3 @@ func PackageRevisionIsReady(readinessGates []porchv1alpha1.ReadinessGate, condit

return true
}

// HasReadinessGate checks if a specific gate exists
func HasReadinessGate(gates []porchv1alpha1.ReadinessGate, gate string) bool {
for i := range gates {
g := gates[i]
if g.ConditionType == gate {
return true
}
}
return false
}
64 changes: 64 additions & 0 deletions controllers/pkg/porch/condition/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,67 @@ func TestHasSpecificTypeConditions(t *testing.T) {
})
}
}

func TestPackageRevisionIsReady(t *testing.T) {
cases := map[string]struct {
conds []porchv1alpha1.Condition
readyGates []porchv1alpha1.ReadinessGate
want bool
}{
"Ready": {
conds: []porchv1alpha1.Condition{
{
Type: "foo",
Status: porchv1alpha1.ConditionStatus(porchv1alpha1.ConditionTrue),
},
{
Type: "foobar",
Status: porchv1alpha1.ConditionStatus(porchv1alpha1.ConditionFalse),
},
{
Type: "myterriblecondition",
Status: porchv1alpha1.ConditionStatus(porchv1alpha1.ConditionFalse),
},
},
readyGates: []porchv1alpha1.ReadinessGate{
{
ConditionType: "foo",
},
},
want: true,
},
"Not ready": {
conds: []porchv1alpha1.Condition{
{
Type: "bar",
Status: porchv1alpha1.ConditionStatus(porchv1alpha1.ConditionFalse),
},
},
readyGates: []porchv1alpha1.ReadinessGate{
{
ConditionType: "bar",
},
},
want: false,
},
"Empty readinessGates": {
conds: []porchv1alpha1.Condition{
{
Type: "bar",
Status: porchv1alpha1.ConditionStatus(porchv1alpha1.ConditionTrue),
},
},
readyGates: []porchv1alpha1.ReadinessGate{},
want: true,
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
b := PackageRevisionIsReady(tc.readyGates, tc.conds)
if diff := cmp.Diff(b, tc.want); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
})
}
}

0 comments on commit 9ec4452

Please sign in to comment.