This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathstack_test.go
More file actions
122 lines (105 loc) · 2.42 KB
/
stack_test.go
File metadata and controls
122 lines (105 loc) · 2.42 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
package main
import (
"bytes"
"encoding/json"
"os"
"reflect"
"testing"
"koding/kites/kloud/provider/aws"
"koding/kites/kloud/stack"
"koding/klientctl/endpoint/stack/stackfixture"
)
func TestStackCreate(t *testing.T) {
cases := map[string]struct {
tmpl []byte
cred string
resp *stack.ImportResponse
}{
"a yaml template": {
stackfixture.StackYAML,
"587265a0bbc81e01cd2f849b",
&stack.ImportResponse{
TemplateID: "5870035a50368f142b105e9f",
StackID: "587003e6d90a2a0a2bc4f385",
Title: "TestStackCreate credential",
},
},
"a json template": {
stackfixture.StackJSON,
"587265adbbc81e01cd2f849c",
&stack.ImportResponse{
TemplateID: "5870035a50368f142b105ea4",
StackID: "53925a609b76835748c0c4fd",
Title: "TestStackCreate credential",
},
},
"a hcl template": {
stackfixture.StackHCL,
"587265b7bbc81e01cd2f849d",
&stack.ImportResponse{
TemplateID: "587003e6d90a2a0a2bc4f384",
StackID: "587003b2d90a2a0a2bc4f380",
Title: "TestStackCreate credential",
},
},
}
for name, cas := range cases {
// capture range variable here
cas := cas
t.Run(name, func(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
cmd := &MainCmd{
Stdin: bytes.NewReader(cas.tmpl),
Stderr: os.Stderr,
Stdout: &buf,
}
defer cmd.Close()
cmd.FT.Add("import", cas.resp)
if err := addCredential(cmd, cas.cred); err != nil {
t.Fatalf("addCredential()=%s", err)
}
err := cmd.Run("stack", "create",
"--file", "-",
"--json",
)
if err != nil {
t.Fatalf("Run()=%s", err)
}
var got stack.ImportResponse
if err := json.Unmarshal(buf.Bytes(), &got); err != nil {
t.Fatalf("Unmarshal()=%s", err)
}
if !reflect.DeepEqual(&got, cas.resp) {
t.Fatalf("got %#v, want %#v", &got, cas.resp)
}
})
}
}
func addCredential(cmd *MainCmd, identifier string) error {
c := cmd.New()
p, err := json.Marshal(&aws.Cred{
AccessKey: "***",
SecretKey: "***",
Region: "us-east-1",
})
if err != nil {
return err
}
c.Stdin = bytes.NewReader(p)
c.Stderr = os.Stderr
c.Stdout = os.Stderr
c.FT.Add("credential.add", &stack.CredentialItem{
Identifier: identifier,
Title: "TestStackCreate credential",
Team: "foobar",
})
return nonil(
c.Run("credential", "create",
"--provider", "aws",
"--team", "foobar",
"--file", "-",
),
c.Run("credential", "use", identifier),
)
}