Skip to content

Commit d3a5439

Browse files
committed
Wire through visibility and name to respective values on API call
1 parent a3840c2 commit d3a5439

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

cmd/create.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import (
1515
type createCmdFlags struct {
1616
app string
1717
name string
18+
visibility string
1819
EnvironmentVariables []string
1920
Secrets []string
2021
RevisionName string
2122
Init bool
2223
}
2324

2425
type createReq struct {
26+
Name string `json:"friendly_name,omitempty"`
27+
Visibility string `json:"visibility,omitempty"`
2528
EnvironmentVariables map[string]string `json:"environment_variables"`
2629
Secrets map[string]string `json:"secrets"`
2730
}
@@ -66,7 +69,8 @@ func init() {
6669
}
6770

6871
createCmd.Flags().StringVarP(&createCmdFlags.app, "app", "a", "", "The app ID to create")
69-
createCmd.Flags().StringVarP(&createCmdFlags.name, "name", "n", "", "The name for the new app")
72+
createCmd.Flags().StringVarP(&createCmdFlags.name, "name", "n", "", "The name for the app")
73+
createCmd.Flags().StringVarP(&createCmdFlags.visibility, "visibility", "v", "", "The visibility of the app (e.g. 'only_owner' or 'github')")
7074
createCmd.Flags().StringSliceVarP(&createCmdFlags.EnvironmentVariables, "env", "e", []string{}, "Environment variables to set on the app in the form 'key=value'")
7175
createCmd.Flags().StringSliceVarP(&createCmdFlags.Secrets, "secret", "s", []string{}, "Secrets to set on the app in the form 'key=value'")
7276
createCmd.Flags().StringVarP(&createCmdFlags.RevisionName, "revision-name", "r", "", "The revision name to use for the app")
@@ -80,6 +84,8 @@ func runCreate(client restClient, flags createCmdFlags) (createResp, error) {
8084
}
8185

8286
requestBody := createReq{
87+
Name: flags.name,
88+
Visibility: flags.visibility,
8389
EnvironmentVariables: map[string]string{},
8490
Secrets: map[string]string{},
8591
}

cmd/create_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ func TestRunCreate_EnvVarWithEqualsInValue(t *testing.T) {
130130

131131
func TestRunCreate_WithName(t *testing.T) {
132132
var capturedPath string
133+
var capturedBody []byte
133134
client := &mockRESTClient{
134-
putFunc: func(path string, _ io.Reader, resp interface{}) error {
135+
putFunc: func(path string, body io.Reader, resp interface{}) error {
135136
capturedPath = path
137+
capturedBody, _ = io.ReadAll(body)
136138
buildCreateResponse(createResp{AppUrl: "https://my-new-app.example.com", ID: "abc-123"}, resp)
137139
return nil
138140
},
@@ -143,6 +145,10 @@ func TestRunCreate_WithName(t *testing.T) {
143145
assert.Equal(t, "https://my-new-app.example.com", resp.AppUrl)
144146
assert.Equal(t, "abc-123", resp.ID)
145147
assert.Equal(t, "runtime", capturedPath)
148+
149+
var req createReq
150+
json.Unmarshal(capturedBody, &req)
151+
assert.Equal(t, "my-new-app", req.Name)
146152
}
147153

148154
func TestRunCreate_WithNameAndInit(t *testing.T) {
@@ -151,8 +157,10 @@ func TestRunCreate_WithNameAndInit(t *testing.T) {
151157
os.Chdir(tmp)
152158
defer os.Chdir(origDir)
153159

160+
var capturedBody []byte
154161
client := &mockRESTClient{
155-
putFunc: func(_ string, _ io.Reader, resp interface{}) error {
162+
putFunc: func(_ string, body io.Reader, resp interface{}) error {
163+
capturedBody, _ = io.ReadAll(body)
156164
buildCreateResponse(createResp{AppUrl: "https://named-app.example.com", ID: "def-456"}, resp)
157165
return nil
158166
},
@@ -161,11 +169,33 @@ func TestRunCreate_WithNameAndInit(t *testing.T) {
161169
_, err := runCreate(client, createCmdFlags{name: "named-app", Init: true})
162170
require.NoError(t, err)
163171

172+
var req createReq
173+
json.Unmarshal(capturedBody, &req)
174+
assert.Equal(t, "named-app", req.Name)
175+
164176
data, err := os.ReadFile("runtime.config.json")
165177
require.NoError(t, err)
166178
assert.Contains(t, string(data), "def-456")
167179
}
168180

181+
func TestRunCreate_WithVisibility(t *testing.T) {
182+
var capturedBody []byte
183+
client := &mockRESTClient{
184+
putFunc: func(_ string, body io.Reader, resp interface{}) error {
185+
capturedBody, _ = io.ReadAll(body)
186+
buildCreateResponse(createResp{AppUrl: "https://my-app.example.com"}, resp)
187+
return nil
188+
},
189+
}
190+
191+
_, err := runCreate(client, createCmdFlags{app: "my-app", visibility: "github"})
192+
require.NoError(t, err)
193+
194+
var req createReq
195+
json.Unmarshal(capturedBody, &req)
196+
assert.Equal(t, "github", req.Visibility)
197+
}
198+
169199
func TestRunCreate_ResponseWithID(t *testing.T) {
170200
client := &mockRESTClient{
171201
putFunc: func(_ string, _ io.Reader, resp interface{}) error {

0 commit comments

Comments
 (0)