Skip to content

Commit 98a23ea

Browse files
committed
test: confirm numeric values from prompt are saved to file
1 parent bac8afa commit 98a23ea

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

cmd/env/add_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,41 @@ func Test_Env_AddCommand(t *testing.T) {
204204
)
205205
},
206206
},
207+
"add a numeric variable using prompts to the .env file": {
208+
CmdArgs: []string{},
209+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
210+
setupEnvAddDotenvMocks(ctx, cm, cf)
211+
cm.IO.On(
212+
"InputPrompt",
213+
mock.Anything,
214+
"Variable name",
215+
mock.Anything,
216+
).Return(
217+
"PORT",
218+
nil,
219+
)
220+
cm.IO.On(
221+
"PasswordPrompt",
222+
mock.Anything,
223+
"Variable value",
224+
iostreams.MatchPromptConfig(iostreams.PasswordPromptConfig{
225+
Flag: cm.Config.Flags.Lookup("value"),
226+
}),
227+
).Return(
228+
iostreams.PasswordPromptResponse{
229+
Prompt: true,
230+
Value: "3000",
231+
},
232+
nil,
233+
)
234+
},
235+
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
236+
cm.API.AssertNotCalled(t, "AddVariable")
237+
content, err := afero.ReadFile(cm.Fs, ".env")
238+
assert.NoError(t, err)
239+
assert.Equal(t, "PORT=3000\n", string(content))
240+
},
241+
},
207242
"add a variable to the .env file for non-hosted app": {
208243
CmdArgs: []string{"NEW_VAR", "new_value"},
209244
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {

0 commit comments

Comments
 (0)