This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.go
60 lines (53 loc) · 1.73 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package util
import (
"fmt"
"io/ioutil"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
buildapi "github.com/openshift/origin/pkg/build/api"
imageapi "github.com/openshift/origin/pkg/image/api"
)
// CreateSampleImageStream creates an ImageStream in given namespace
func CreateSampleImageStream(namespace string) *imageapi.ImageStream {
var stream imageapi.ImageStream
jsonData, err := ioutil.ReadFile("fixtures/test-image-stream.json")
if err != nil {
fmt.Printf("ERROR: Unable to read: %v", err)
return nil
}
latest.Codec.DecodeInto(jsonData, &stream)
client, _ := GetClusterAdminClient(KubeConfigPath())
result, err := client.ImageStreams(namespace).Create(&stream)
if err != nil {
fmt.Printf("ERROR: Unable to create sample ImageStream: %v\n", err)
return nil
}
return result
}
// DeleteSampleImageStream removes the ImageStream created in given
// namespace
func DeleteSampleImageStream(stream *imageapi.ImageStream, namespace string) {
client, _ := GetClusterAdminClient(KubeConfigPath())
client.ImageStreams(namespace).Delete(stream.Name)
}
// GetBuildFixture reads the Build JSON and returns and Build object
func GetBuildFixture(filename string) *buildapi.Build {
var build buildapi.Build
jsonData, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Printf("ERROR: Unable to read %s: %v", filename, err)
return nil
}
latest.Codec.DecodeInto(jsonData, &build)
return &build
}
func GetSecretFixture(filename string) *kapi.Secret {
var secret kapi.Secret
jsonData, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Printf("ERROR: Unable to read %s: %v", filename, err)
return nil
}
latest.Codec.DecodeInto(jsonData, &secret)
return &secret
}