-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathyaml_test.go
More file actions
99 lines (94 loc) · 2.42 KB
/
Copy pathyaml_test.go
File metadata and controls
99 lines (94 loc) · 2.42 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package iapetus
import (
"os"
"testing"
)
func TestLoadWorkflowFromYAML_Success(t *testing.T) {
yamlContent := `
name: test-wf
backend: bash
env_map:
FOO: bar
steps:
- name: step1
command: echo
args: ["hello"]
timeout: 1s
backend: bash
env_map:
BAR: baz
raw_asserts:
- exit_code: 0
- output_contains: hello
- output_equals: "hello\n"
- output_json_equals: '{"foo": 1}'
- output_matches_regexp: '^hello.*$'
- output_json_equals: '{"foo": 1}'
skip_json_nodes: ["foo.bar"]
- name: step2
command: echo
args: ["world"]
depends: [step1]
raw_asserts:
- output_equals: "world\n"
`
f, err := os.CreateTemp("", "iapetus_yaml_test_*.yaml")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
defer os.Remove(f.Name())
if _, err := f.WriteString(yamlContent); err != nil {
t.Fatalf("failed to write yaml: %v", err)
}
f.Close()
wf, err := LoadWorkflowFromYAML(f.Name())
if err != nil {
t.Fatalf("LoadWorkflowFromYAML failed: %v", err)
}
if wf.Name != "test-wf" {
t.Errorf("expected workflow name 'test-wf', got %q", wf.Name)
}
if wf.Backend != "bash" {
t.Errorf("expected backend 'bash', got %q", wf.Backend)
}
if wf.EnvMap["FOO"] != "bar" {
t.Errorf("expected env_map FOO=bar, got %v", wf.EnvMap)
}
if len(wf.Steps) != 2 {
t.Fatalf("expected 2 steps, got %d", len(wf.Steps))
}
step1 := wf.Steps[0]
if step1.Name != "step1" || step1.Command != "echo" {
t.Errorf("unexpected step1: %+v", step1)
}
if step1.Timeout.Seconds() != 1 {
t.Errorf("expected timeout 1s, got %v", step1.Timeout)
}
if step1.EnvMap["BAR"] != "baz" {
t.Errorf("expected env_map BAR=baz, got %v", step1.EnvMap)
}
if len(step1.Asserts) != 6 {
t.Errorf("expected 6 assertions, got %d", len(step1.Asserts))
}
}
func TestLoadWorkflowFromYAML_FileNotFound(t *testing.T) {
_, err := LoadWorkflowFromYAML("nonexistent.yaml")
if err == nil {
t.Error("expected error for missing file, got nil")
}
}
func TestLoadWorkflowFromYAML_InvalidYAML(t *testing.T) {
f, err := os.CreateTemp("", "iapetus_yaml_test_invalid_*.yaml")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
defer os.Remove(f.Name())
if _, err := f.WriteString("not: [valid: yaml"); err != nil {
t.Fatalf("failed to write yaml: %v", err)
}
f.Close()
_, err = LoadWorkflowFromYAML(f.Name())
if err == nil {
t.Error("expected error for invalid yaml, got nil")
}
}