-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
61 lines (53 loc) · 1.38 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
package test
import (
"io/ioutil"
"path/filepath"
"runtime"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/ghodss/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
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 {
var wf wfv1.Workflow
err := yaml.Unmarshal(yamlBytes, &wf)
if err != nil {
panic(err)
}
return &wf
}
// LoadUnstructuredFromBytes returns an Unstructured unmarshalled from an yaml byte array
func LoadUnstructuredFromBytes(yamlBytes []byte) *unstructured.Unstructured {
var un unstructured.Unstructured
err := yaml.Unmarshal(yamlBytes, &un)
if err != nil {
panic(err)
}
return &un
}