-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add running workflow for worker index to cache
* Add tests on index functions Signed-off-by: Micah Hausler <[email protected]>
- Loading branch information
1 parent
e1e2af6
commit 1e2fb3f
Showing
2 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package controllers | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func TestWokerIndexFunc(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input client.Object | ||
want []string | ||
}{ | ||
{ | ||
"non workflow", | ||
&v1alpha1.Hardware{}, | ||
nil, | ||
}, | ||
{ | ||
"empty workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "", | ||
Tasks: []v1alpha1.Task{}, | ||
}, | ||
}, | ||
[]string{}, | ||
}, | ||
{ | ||
"pending workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_PENDING", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{"worker1"}, | ||
}, | ||
{ | ||
"running workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_RUNNING", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
{ | ||
WorkerAddr: "worker2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{"worker1", "worker2"}, | ||
}, | ||
{ | ||
"complete workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_SUCCESS", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{"worker1"}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := wokerIndexFunc(tc.input) | ||
if !reflect.DeepEqual(tc.want, got) { | ||
t.Errorf("Unexpected response: wanted %#v, got %#v", tc.want, got) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNonTerminalStateForWorkerIndexFunc(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input client.Object | ||
want []string | ||
}{ | ||
{ | ||
"non workflow", | ||
&v1alpha1.Hardware{}, | ||
nil, | ||
}, | ||
{ | ||
"empty workflow status", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{}, | ||
}, | ||
{ | ||
"pending workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_PENDING", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{"worker1"}, | ||
}, | ||
{ | ||
"running workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_RUNNING", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
{ | ||
WorkerAddr: "worker2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{"worker1", "worker2"}, | ||
}, | ||
{ | ||
"complete workflow", | ||
&v1alpha1.Workflow{ | ||
Status: v1alpha1.WorkflowStatus{ | ||
State: "STATE_SUCCESS", | ||
Tasks: []v1alpha1.Task{ | ||
{ | ||
WorkerAddr: "worker1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]string{}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := nonTerminalStateForWorkerIndexFunc(tc.input) | ||
if !reflect.DeepEqual(tc.want, got) { | ||
t.Errorf("Unexpected response: wanted %#v, got %#v", tc.want, got) | ||
} | ||
}) | ||
} | ||
} |