|
3 | 3 | package tests |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "encoding/json" |
| 7 | + "io/ioutil" |
| 8 | + "os/user" |
| 9 | + "path" |
6 | 10 | "testing" |
7 | 11 |
|
8 | 12 | "github.com/deis/deis/tests/utils" |
9 | 13 | ) |
10 | 14 |
|
| 15 | +const clientJsonFilePath string = ".deis/client.json" |
| 16 | + |
11 | 17 | var ( |
12 | 18 | gitCloneCmd = "if [ ! -d {{.ExampleApp}} ] ; then git clone https://github.com/deis/{{.ExampleApp}}.git ; fi" |
13 | 19 | gitRemoveCmd = "git remote remove deis" |
14 | 20 | gitPushCmd = "git push deis master" |
15 | 21 | ) |
16 | 22 |
|
| 23 | +// Client represents the client data structure in ~/.deis/client.json |
| 24 | +type Client struct { |
| 25 | + Controller string `json:"controller"` |
| 26 | + Username string `json:"username"` |
| 27 | + Token string `json:"token"` |
| 28 | +} |
| 29 | + |
17 | 30 | func TestGlobal(t *testing.T) { |
18 | 31 | params := utils.GetGlobalConfig() |
19 | 32 | utils.Execute(t, authRegisterCmd, params, false, "") |
| 33 | + clientTest(t, params) |
20 | 34 | utils.Execute(t, keysAddCmd, params, false, "") |
21 | 35 | } |
| 36 | + |
| 37 | +func clientTest(t *testing.T, params *utils.DeisTestConfig) { |
| 38 | + user, err := user.Current() |
| 39 | + if err != nil { |
| 40 | + t.Fatal(err) |
| 41 | + } |
| 42 | + data, err := ioutil.ReadFile(path.Join(user.HomeDir, clientJsonFilePath)) |
| 43 | + if err != nil { |
| 44 | + t.Fatal(err) |
| 45 | + } |
| 46 | + client := &Client{} |
| 47 | + json.Unmarshal(data, &client) |
| 48 | + if client.Token == "" { |
| 49 | + t.Error("token not present in client.json") |
| 50 | + } |
| 51 | + if client.Controller == "" { |
| 52 | + t.Error("controller endpoint not present in client.json") |
| 53 | + } |
| 54 | + if client.Username == "" { |
| 55 | + t.Error("username not present in client.json") |
| 56 | + } |
| 57 | +} |
0 commit comments