@@ -260,6 +260,59 @@ func Test_CLI_Env_Values_MultipleEnvironments(t *testing.T) {
260
260
require .Equal (t , values ["envName2" ], envName2 )
261
261
}
262
262
263
+ func Test_CLI_Env_GetValue (t * testing.T ) {
264
+ ctx , cancel := newTestContext (t )
265
+ defer cancel ()
266
+
267
+ dir := tempDirWithDiagnostics (t )
268
+ t .Logf ("DIR: %s" , dir )
269
+
270
+ cli := azdcli .NewCLI (t )
271
+ cli .WorkingDirectory = dir
272
+
273
+ err := copySample (dir , "storage" )
274
+ require .NoError (t , err , "failed expanding sample" )
275
+
276
+ // Create an environment
277
+ envName := randomEnvName ()
278
+ envNew (ctx , t , cli , envName , false )
279
+
280
+ // Set key1
281
+ envSetValue (ctx , t , cli , "key1" , "value1" )
282
+
283
+ // Get key1 value
284
+ value := envGetValue (ctx , t , cli , "key1" )
285
+ require .Equal (t , "value1" , value )
286
+
287
+ // Set key2
288
+ envSetValue (ctx , t , cli , "key2" , "value2" )
289
+
290
+ // Get key2 value
291
+ value = envGetValue (ctx , t , cli , "key2" )
292
+ require .Equal (t , "value2" , value )
293
+
294
+ // Modify key1
295
+ envSetValue (ctx , t , cli , "key1" , "modified1" )
296
+
297
+ // Get modified key1 value
298
+ value = envGetValue (ctx , t , cli , "key1" )
299
+ require .Equal (t , "modified1" , value )
300
+
301
+ // Test non-existent key
302
+ res , err := cli .RunCommand (ctx , "env" , "get-value" , "non_existent_key" )
303
+ require .Error (t , err )
304
+ require .Contains (t , res .Stdout , "key 'non_existent_key' not found in the environment values" )
305
+ }
306
+
307
+ func envGetValue (ctx context.Context , t * testing.T , cli * azdcli.CLI , key string ) string {
308
+ args := []string {"env" , "get-value" , key }
309
+
310
+ result , err := cli .RunCommand (ctx , args ... )
311
+ require .NoError (t , err )
312
+
313
+ return strings .TrimSpace (result .Stdout )
314
+ }
315
+
263
316
func requireIsDefault (t * testing.T , list []contracts.EnvListEnvironment , envName string ) {
264
317
for _ , env := range list {
265
318
if env .Name == envName {
0 commit comments