-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_test.go
62 lines (46 loc) · 1.47 KB
/
types_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present Harry Randazzo
package vai
import (
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/require"
)
// do not make changes to this variable within tests
var helloWorldWorkflow = Workflow{
"default": {Step{Run: "echo 'Hello World!'"}},
"a-task": {Step{Run: "echo 'task a'"}},
"task-b": {Step{Run: "echo 'task b'"}},
}
func TestWorkflowFind(t *testing.T) {
task, ok := helloWorldWorkflow.Find(DefaultTaskName)
require.True(t, ok)
require.Len(t, task, 1)
require.Equal(t, "echo 'Hello World!'", task[0].Run)
task, ok = helloWorldWorkflow.Find("foo")
require.Nil(t, task)
require.False(t, ok)
}
func TestOrderedTaskNames(t *testing.T) {
names := helloWorldWorkflow.OrderedTaskNames()
expected := []string{"default", "a-task", "task-b"}
require.ElementsMatch(t, expected, names)
wf := Workflow{"foo": nil, "bar": nil, "baz": nil, "default": nil}
names = wf.OrderedTaskNames()
expected = []string{"default", "bar", "baz", "foo"}
require.ElementsMatch(t, expected, names)
delete(wf, "default")
names = wf.OrderedTaskNames()
expected = []string{"bar", "baz", "foo"}
require.ElementsMatch(t, expected, names)
}
func TestWorkflowSchemaGen(t *testing.T) {
schema := WorkFlowSchema()
require.NotNil(t, schema)
b, err := json.Marshal(schema)
require.NoError(t, err)
current, err := os.ReadFile("vai.schema.json")
require.NoError(t, err)
require.JSONEq(t, string(current), string(b))
}