osbuild-service-maintenance: add test for allTerminated
HMS-3632
This commit is contained in:
parent
65b7ee65b2
commit
24e256c225
2 changed files with 77 additions and 0 deletions
|
|
@ -125,3 +125,79 @@ func TestCheckValidParent(t *testing.T) {
|
|||
require.Equal(t, tc.result, main.CheckValidParent("testChildId", tc.parent))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllTerminated(t *testing.T) {
|
||||
tests :=
|
||||
[]struct {
|
||||
reservations []ec2types.Reservation
|
||||
result bool
|
||||
}{
|
||||
// no reservations
|
||||
{
|
||||
reservations: []ec2types.Reservation{},
|
||||
result: true,
|
||||
},
|
||||
// no instances
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{}},
|
||||
},
|
||||
result: true,
|
||||
},
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{{}, {}}},
|
||||
},
|
||||
result: true,
|
||||
},
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{{
|
||||
State: &ec2types.InstanceState{
|
||||
Name: ec2types.InstanceStateNamePending,
|
||||
},
|
||||
}}},
|
||||
},
|
||||
result: false,
|
||||
},
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{{
|
||||
State: &ec2types.InstanceState{
|
||||
Name: ec2types.InstanceStateNameRunning,
|
||||
},
|
||||
}}},
|
||||
},
|
||||
result: false,
|
||||
},
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{{
|
||||
State: &ec2types.InstanceState{
|
||||
Name: ec2types.InstanceStateNameRunning,
|
||||
},
|
||||
},
|
||||
{
|
||||
State: &ec2types.InstanceState{
|
||||
Name: ec2types.InstanceStateNameTerminated,
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
result: false,
|
||||
},
|
||||
{
|
||||
reservations: []ec2types.Reservation{
|
||||
{Instances: []ec2types.Instance{{
|
||||
State: &ec2types.InstanceState{
|
||||
Name: ec2types.InstanceStateNameTerminated,
|
||||
},
|
||||
}}},
|
||||
},
|
||||
result: true,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
require.Equal(t, tc.result, main.AllTerminated(tc.reservations))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ package main
|
|||
|
||||
var FilterOnTooOld = filterOnTooOld
|
||||
var CheckValidParent = checkValidParent
|
||||
var AllTerminated = allTerminated
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue