forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
44 lines (39 loc) · 1009 Bytes
/
helpers.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
package util
import (
"io/ioutil"
"k8s.io/apimachinery/pkg/runtime"
kyaml "k8s.io/apimachinery/pkg/util/yaml"
kapi "k8s.io/kubernetes/pkg/api"
imageapi "github.com/openshift/origin/pkg/image/api"
templateapi "github.com/openshift/origin/pkg/template/api"
)
func GetTemplateFixture(filename string) (*templateapi.Template, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
jsonData, err := kyaml.ToJSON(data)
if err != nil {
return nil, err
}
obj, err := runtime.Decode(kapi.Codecs.UniversalDecoder(), jsonData)
if err != nil {
return nil, err
}
return obj.(*templateapi.Template), nil
}
func GetImageFixture(filename string) (*imageapi.Image, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
jsonData, err := kyaml.ToJSON(data)
if err != nil {
return nil, err
}
obj, err := runtime.Decode(kapi.Codecs.UniversalDecoder(), jsonData)
if err != nil {
return nil, err
}
return obj.(*imageapi.Image), nil
}