-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathconfig_test.go
More file actions
73 lines (55 loc) · 1.5 KB
/
config_test.go
File metadata and controls
73 lines (55 loc) · 1.5 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
package config
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/deis/deis/client-go/controller/client"
"github.com/deis/deis/version"
)
const configSetExpected string = `{"values":{"FOO":"bar","TEST":"yes"}}`
type fakeHTTPServer struct{}
func (f *fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
res.Header().Add("DEIS_API_VERSION", version.APIVersion)
if req.URL.Path == "/v1/apps/example-go/config" && req.Method == "POST" {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
fmt.Println(err)
res.WriteHeader(http.StatusInternalServerError)
res.Write(nil)
}
if string(body) != configSetExpected {
fmt.Printf("Expected '%s', Got '%s'\n", configSetExpected, body)
res.WriteHeader(http.StatusInternalServerError)
res.Write(nil)
return
}
res.WriteHeader(http.StatusCreated)
res.Write([]byte(`[0,"hi\n"]`))
return
}
fmt.Printf("Unrecongized URL %s\n", req.URL)
res.WriteHeader(http.StatusNotFound)
res.Write(nil)
}
func TestConfigSet(t *testing.T) {
t.Parallel()
handler := fakeHTTPServer{}
server := httptest.NewServer(&handler)
defer server.Close()
u, err := url.Parse(server.URL)
if err != nil {
t.Fatal(err)
}
httpClient := client.CreateHTTPClient(false)
client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
testVars := map[string]string{
"TEST": "yes",
"FOO": "bar",
}
if err = Set(&client, "example-go", testVars); err != nil {
t.Error(err)
}
}