-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathconfig_test.go
More file actions
154 lines (115 loc) · 3.3 KB
/
config_test.go
File metadata and controls
154 lines (115 loc) · 3.3 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package config
import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/deis/deis/deisctl/config/model"
"github.com/deis/deis/deisctl/test/mock"
)
func TestGetConfig(t *testing.T) {
t.Parallel()
testMock := mock.ConfigBackend{Expected: []*model.ConfigNode{{Key: "/deis/controller/testing", Value: "foo"}, {Key: "/deis/controller/port", Value: "8000"}}}
testWriter := bytes.Buffer{}
err := doConfig("controller", "get", []string{"testing", "port"}, testMock, &testWriter)
if err != nil {
t.Fatal(err)
}
expected := "foo\n8000\n"
output := testWriter.String()
if output != expected {
t.Error(fmt.Errorf("Expected: '%s', Got:'%s'", expected, output))
}
}
func TestGetConfigError(t *testing.T) {
t.Parallel()
testMock := mock.ConfigBackend{Expected: []*model.ConfigNode{{Key: "/deis/controller/testing", Value: "foo"}}}
testWriter := bytes.Buffer{}
err := doConfig("controller", "get", []string{"port"}, testMock, &testWriter)
if err == nil {
t.Fatal("Error Expected")
}
}
func TestSetConfig(t *testing.T) {
t.Parallel()
testMock := mock.ConfigBackend{Expected: []*model.ConfigNode{{Key: "/deis/controller/testing", Value: "foo"}, {Key: "/deis/controller/port", Value: "8000"}}}
testWriter := bytes.Buffer{}
err := doConfig("controller", "set", []string{"testing=bar", "port=1000"}, testMock, &testWriter)
if err != nil {
t.Fatal(err)
}
expected := "bar\n1000\n"
output := testWriter.String()
if output != expected {
t.Error(fmt.Errorf("Expected: '%s', Got:'%s'", expected, output))
}
}
func TestDeleteConfig(t *testing.T) {
t.Parallel()
testMock := mock.ConfigBackend{Expected: []*model.ConfigNode{{Key: "/deis/controller/testing", Value: "foo"}, {Key: "/deis/controller/port", Value: "8000"}}}
testWriter := bytes.Buffer{}
err := doConfig("controller", "rm", []string{"testing", "port"}, testMock, &testWriter)
if err != nil {
t.Fatal(err)
}
expected := "testing\nport\n"
output := testWriter.String()
if output != expected {
t.Error(fmt.Errorf("Expected: '%s', Got:'%s'", expected, output))
}
}
// TestConfigSSHPrivateKey ensures private keys are base64 encoded from file path
func TestConfigSSHPrivateKey(t *testing.T) {
t.Parallel()
f, err := writeTempFile("private-key")
if err != nil {
t.Fatal(err)
}
val, err := valueForPath("/deis/platform/sshPrivateKey", f.Name())
if err != nil {
t.Fatal(err)
}
encoded := base64.StdEncoding.EncodeToString([]byte("private-key"))
if val != encoded {
t.Fatalf("expected: %v, got: %v", encoded, val)
}
}
func TestConfigRouterKey(t *testing.T) {
t.Parallel()
f, err := writeTempFile("router-key")
if err != nil {
t.Fatal(err)
}
val, err := valueForPath("/deis/router/sslKey", f.Name())
if err != nil {
t.Fatal(err)
}
if val != "router-key" {
t.Fatalf("expected: router-key, got: %v", val)
}
}
func TestConfigRouterCert(t *testing.T) {
t.Parallel()
f, err := writeTempFile("router-cert")
if err != nil {
t.Fatal(err)
}
val, err := valueForPath("/deis/router/sslCert", f.Name())
if err != nil {
t.Fatal(err)
}
if val != "router-cert" {
t.Fatalf("expected: router-cert, got: %v", val)
}
}
func writeTempFile(data string) (*os.File, error) {
f, err := ioutil.TempFile("", "deisctl")
if err != nil {
return nil, err
}
f.Write([]byte(data))
defer f.Close()
return f, nil
}