@@ -363,22 +363,46 @@ func TestCommandName(t *testing.T) {
363363 assert .NoError (t , err )
364364}
365365
366- // Test both cases of the ExecAndReportUsage function
367- // Usage should be sent only when the environment variable is set
368- // Validate no errors
369366func TestConfigCommand_ExecAndReportUsage (t * testing.T ) {
370- // With usage report
371- err := os .Setenv (coreutils .UsageOidcConfigured , "TRUE" )
372- assert .NoError (t , err )
373- cc := NewConfigCommand (AddOrEdit , testServerId )
374- err = cc .ExecAndReportUsage ()
375- assert .NoError (t , err )
376- // Without usage report
377- err = os .Unsetenv (coreutils .UsageOidcConfigured )
378- assert .NoError (t , err )
379- cc = NewConfigCommand (AddOrEdit , testServerId )
380- err = cc .ExecAndReportUsage ()
381- assert .NoError (t , err )
367+ // Define test scenarios
368+ testCases := []struct {
369+ name string
370+ envVarValue string // Environment variable value to set (or empty to unset)
371+ expectedName string // Expected command name
372+ expectError bool // Whether an error is expected
373+ }{
374+ {
375+ name : "With usage report" ,
376+ envVarValue : "TRUE" ,
377+ expectedName : ConfigOIDCConfiguredCommandName ,
378+ },
379+ {
380+ name : "Without usage report" ,
381+ envVarValue : "" , // Empty to unset the environment variable
382+ expectedName : ConfigCommandName ,
383+ },
384+ }
385+
386+ for _ , tc := range testCases {
387+ t .Run (tc .name , func (t * testing.T ) {
388+ // Set or unset the environment variable
389+ if tc .envVarValue != "" {
390+ err := os .Setenv (coreutils .UsageOidcConfigured , tc .envVarValue )
391+ assert .NoError (t , err )
392+ } else {
393+ err := os .Unsetenv (coreutils .UsageOidcConfigured )
394+ assert .NoError (t , err )
395+ }
396+
397+ // Initialize the command and check the expected command name
398+ cc := NewConfigCommand (AddOrEdit , testServerId )
399+ assert .Equal (t , tc .expectedName , cc .CommandName ())
400+
401+ // Execute and validate no errors
402+ err := cc .ExecAndReportUsage ()
403+ assert .NoError (t , err )
404+ })
405+ }
382406}
383407
384408func testExportImport (t * testing.T , inputDetails * config.ServerDetails ) {
0 commit comments