@@ -205,57 +205,17 @@ func Test_Env_AddCommand(t *testing.T) {
205205 },
206206 },
207207 "add a variable to the .env file for non-hosted app" : {
208- CmdArgs : []string {"ENV_NAME" , "ENV_VALUE" },
209- Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
210- setupEnvAddDotenvMocks (ctx , cm , cf )
211- },
212- ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
213- cm .API .AssertNotCalled (t , "AddVariable" )
214- cm .IO .AssertCalled (
215- t ,
216- "PrintTrace" ,
217- mock .Anything ,
218- slacktrace .EnvAddSuccess ,
219- mock .Anything ,
220- )
221- },
222- },
223- "add a variable preserving existing variables and comments in .env" : {
224208 CmdArgs : []string {"NEW_VAR" , "new_value" },
225209 Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
226210 setupEnvAddDotenvMocks (ctx , cm , cf )
227- err := afero .WriteFile (cf .Fs , ".env" , []byte ("# Config\n EXISTING=value\n " ), 0644 )
211+ err := afero .WriteFile (cf .Fs , ".env" , []byte ("# Config\n EXISTING=value\n " ), 0600 )
228212 assert .NoError (t , err )
229213 },
230214 ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
231215 cm .API .AssertNotCalled (t , "AddVariable" )
232- },
233- },
234- "overwrite an existing variable in .env file" : {
235- CmdArgs : []string {"MY_VAR" , "new_value" },
236- Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
237- setupEnvAddDotenvMocks (ctx , cm , cf )
238- err := afero .WriteFile (cf .Fs , ".env" , []byte ("MY_VAR=old_value\n " ), 0644 )
216+ content , err := afero .ReadFile (cm .Fs , ".env" )
239217 assert .NoError (t , err )
240- },
241- ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
242- cm .API .AssertNotCalled (t , "AddVariable" )
243- },
244- },
245- "create .env file when it does not exist" : {
246- CmdArgs : []string {"FIRST_VAR" , "first_value" },
247- Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
248- setupEnvAddDotenvMocks (ctx , cm , cf )
249- },
250- ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
251- cm .API .AssertNotCalled (t , "AddVariable" )
252- cm .IO .AssertCalled (
253- t ,
254- "PrintTrace" ,
255- mock .Anything ,
256- slacktrace .EnvAddSuccess ,
257- mock .Anything ,
258- )
218+ assert .Equal (t , "# Config\n EXISTING=value\n NEW_VAR=\" new_value\" \n " , string (content ))
259219 },
260220 },
261221 }, func (cf * shared.ClientFactory ) * cobra.Command {
0 commit comments