forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
50 lines (42 loc) · 962 Bytes
/
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
package test
import (
"io/ioutil"
"path/filepath"
"runtime"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/ghodss/yaml"
)
var (
testDir string
)
func init() {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("could not determine test directory")
}
testDir = filepath.Dir(filename)
}
// LoadE2EWorkflow returns a test workflow by it's path
func LoadE2EWorkflow(path string) *wfv1.Workflow {
yamlBytes, err := ioutil.ReadFile(filepath.Join(testDir, "e2e", path))
if err != nil {
panic(err)
}
return unmarshalWF(yamlBytes)
}
// LoadTestWorkflow returns a workflow relative to the test file
func LoadTestWorkflow(path string) *wfv1.Workflow {
yamlBytes, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return unmarshalWF(yamlBytes)
}
func unmarshalWF(yamlBytes []byte) *wfv1.Workflow {
var wf wfv1.Workflow
err := yaml.Unmarshal(yamlBytes, &wf)
if err != nil {
panic(err)
}
return &wf
}