forked from argoproj/argo-workflows
/
test.go
69 lines (59 loc) · 1.72 KB
/
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
63
64
65
66
67
68
69
package test
import (
"io/ioutil"
"path/filepath"
"runtime"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/test/util"
)
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 LoadWorkflowFromBytes(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 LoadWorkflowFromBytes(yamlBytes)
}
// LoadWorkflowFromBytes returns a workflow unmarshalled from an yaml byte array
func LoadWorkflowFromBytes(yamlBytes []byte) *wfv1.Workflow {
v := &wfv1.Workflow{}
util.MustUnmarshallYAML(string(yamlBytes), v)
return v
}
// LoadTestWorkflow returns a workflow relative to the test file
func LoadTestWorkflowTemplate(path string) *wfv1.WorkflowTemplate {
yamlBytes, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return LoadWorkflowTemplateFromBytes(yamlBytes)
}
// LoadWorkflowFromBytes returns a workflow unmarshalled from an yaml byte array
func LoadWorkflowTemplateFromBytes(yamlBytes []byte) *wfv1.WorkflowTemplate {
v := &wfv1.WorkflowTemplate{}
util.MustUnmarshallYAML(string(yamlBytes), v)
return v
}
func LoadClusterWorkflowTemplateFromBytes(yamlBytes []byte) *wfv1.ClusterWorkflowTemplate {
v := &wfv1.ClusterWorkflowTemplate{}
util.MustUnmarshallYAML(string(yamlBytes), v)
return v
}