@@ -301,3 +301,197 @@ func TestConfigSource(t *testing.T) {
301301 t .Errorf ("expected source 'unknown' for bogus key, got %q" , got )
302302 }
303303}
304+
305+ func TestConfigSetEventKey (t * testing.T ) {
306+ tmp := t .TempDir ()
307+ cfgPath := filepath .Join (tmp , "cli.json" )
308+ config .ResetForTest ()
309+ t .Setenv ("INNGEST_CLI_CONFIG" , cfgPath )
310+
311+ state .Config = & config.Config {}
312+ state .Output = "json"
313+
314+ cmd := NewConfigCmd ()
315+ cmd .SetArgs ([]string {"set" , "event_key" , "my-event-key-123" })
316+ cmd .SetOut (& bytes.Buffer {})
317+ cmd .SetErr (& bytes.Buffer {})
318+
319+ var out string
320+ var execErr error
321+ out = captureStdout (t , func () {
322+ execErr = cmd .Execute ()
323+ })
324+ if execErr != nil {
325+ t .Fatalf ("unexpected error: %v" , execErr )
326+ }
327+
328+ if state .Config .EventKey != "my-event-key-123" {
329+ t .Errorf ("expected EventKey %q, got %q" , "my-event-key-123" , state .Config .EventKey )
330+ }
331+ // Event key should be redacted in output
332+ if strings .Contains (out , "my-event-key-123" ) {
333+ t .Error ("output contains unredacted event key" )
334+ }
335+ }
336+
337+ func TestConfigSetAPIBaseURL (t * testing.T ) {
338+ tmp := t .TempDir ()
339+ cfgPath := filepath .Join (tmp , "cli.json" )
340+ config .ResetForTest ()
341+ t .Setenv ("INNGEST_CLI_CONFIG" , cfgPath )
342+
343+ state .Config = & config.Config {}
344+ state .Output = "json"
345+
346+ cmd := NewConfigCmd ()
347+ cmd .SetArgs ([]string {"set" , "api_base_url" , "https://custom.inngest.com" })
348+ cmd .SetOut (& bytes.Buffer {})
349+ cmd .SetErr (& bytes.Buffer {})
350+
351+ var execErr error
352+ captureStdout (t , func () {
353+ execErr = cmd .Execute ()
354+ })
355+ if execErr != nil {
356+ t .Fatalf ("unexpected error: %v" , execErr )
357+ }
358+
359+ if state .Config .APIBaseURL != "https://custom.inngest.com" {
360+ t .Errorf ("expected APIBaseURL %q, got %q" , "https://custom.inngest.com" , state .Config .APIBaseURL )
361+ }
362+ }
363+
364+ func TestConfigSetDevServerURL (t * testing.T ) {
365+ tmp := t .TempDir ()
366+ cfgPath := filepath .Join (tmp , "cli.json" )
367+ config .ResetForTest ()
368+ t .Setenv ("INNGEST_CLI_CONFIG" , cfgPath )
369+
370+ state .Config = & config.Config {}
371+ state .Output = "json"
372+
373+ cmd := NewConfigCmd ()
374+ cmd .SetArgs ([]string {"set" , "dev_server_url" , "http://localhost:9999" })
375+ cmd .SetOut (& bytes.Buffer {})
376+ cmd .SetErr (& bytes.Buffer {})
377+
378+ var execErr error
379+ captureStdout (t , func () {
380+ execErr = cmd .Execute ()
381+ })
382+ if execErr != nil {
383+ t .Fatalf ("unexpected error: %v" , execErr )
384+ }
385+
386+ if state .Config .DevServerURL != "http://localhost:9999" {
387+ t .Errorf ("expected DevServerURL %q, got %q" , "http://localhost:9999" , state .Config .DevServerURL )
388+ }
389+ }
390+
391+ func TestConfigSetInvalidKey (t * testing.T ) {
392+ state .Config = & config.Config {}
393+ state .Output = "json"
394+
395+ cmd := NewConfigCmd ()
396+ cmd .SetArgs ([]string {"set" , "bogus_key" , "value" })
397+ cmd .SetOut (& bytes.Buffer {})
398+ cmd .SetErr (& bytes.Buffer {})
399+
400+ err := cmd .Execute ()
401+ if err == nil {
402+ t .Fatal ("expected error for invalid config key" )
403+ }
404+ if ! strings .Contains (err .Error (), "unrecognized config key" ) {
405+ t .Errorf ("expected error about unrecognized key, got: %v" , err )
406+ }
407+ }
408+
409+ func TestConfigSetValidSigningKey (t * testing.T ) {
410+ tmp := t .TempDir ()
411+ cfgPath := filepath .Join (tmp , "cli.json" )
412+ config .ResetForTest ()
413+ t .Setenv ("INNGEST_CLI_CONFIG" , cfgPath )
414+
415+ state .Config = & config.Config {}
416+ state .Output = "json"
417+
418+ cmd := NewConfigCmd ()
419+ cmd .SetArgs ([]string {"set" , "signing_key" , "signkey-test-valid123" })
420+ cmd .SetOut (& bytes.Buffer {})
421+ cmd .SetErr (& bytes.Buffer {})
422+
423+ var execErr error
424+ captureStdout (t , func () {
425+ execErr = cmd .Execute ()
426+ })
427+ if execErr != nil {
428+ t .Fatalf ("unexpected error: %v" , execErr )
429+ }
430+
431+ if state .Config .SigningKey != "signkey-test-valid123" {
432+ t .Errorf ("expected SigningKey %q, got %q" , "signkey-test-valid123" , state .Config .SigningKey )
433+ }
434+ }
435+
436+ func TestGetConfigValue_AllKeys (t * testing.T ) {
437+ cfg := & config.Config {
438+ SigningKey : "signkey-test-123" ,
439+ EventKey : "evt-key-123" ,
440+ ActiveEnv : "staging" ,
441+ APIBaseURL : "https://custom.api.com" ,
442+ DevServerURL : "http://localhost:9999" ,
443+ }
444+
445+ tests := []struct {
446+ key string
447+ expected string
448+ }{
449+ {"signing_key" , "signkey-test-123" },
450+ {"event_key" , "evt-key-123" },
451+ {"active_env" , "staging" },
452+ {"api_base_url" , "https://custom.api.com" },
453+ {"dev_server_url" , "http://localhost:9999" },
454+ {"unknown_key" , "" },
455+ }
456+
457+ for _ , tt := range tests {
458+ t .Run (tt .key , func (t * testing.T ) {
459+ got := getConfigValue (cfg , tt .key )
460+ if got != tt .expected {
461+ t .Errorf ("getConfigValue(%q) = %q, want %q" , tt .key , got , tt .expected )
462+ }
463+ })
464+ }
465+ }
466+
467+ func TestConfigSource_AllKeys (t * testing.T ) {
468+ t .Setenv ("INNGEST_SIGNING_KEY" , "" )
469+ t .Setenv ("INNGEST_EVENT_KEY" , "" )
470+
471+ cfg := & config.Config {
472+ APIBaseURL : "https://custom.api.com" ,
473+ DevServerURL : "http://localhost:9999" ,
474+ }
475+
476+ if got := configSource (cfg , "api_base_url" ); got != "config" {
477+ t .Errorf ("expected source 'config' for api_base_url, got %q" , got )
478+ }
479+ if got := configSource (cfg , "dev_server_url" ); got != "config" {
480+ t .Errorf ("expected source 'config' for dev_server_url, got %q" , got )
481+ }
482+
483+ cfg2 := & config.Config {}
484+ if got := configSource (cfg2 , "api_base_url" ); got != "default" {
485+ t .Errorf ("expected source 'default' for empty api_base_url, got %q" , got )
486+ }
487+ if got := configSource (cfg2 , "dev_server_url" ); got != "default" {
488+ t .Errorf ("expected source 'default' for empty dev_server_url, got %q" , got )
489+ }
490+
491+ // event_key from env
492+ t .Setenv ("INNGEST_EVENT_KEY" , "evt-from-env" )
493+ cfg3 := & config.Config {}
494+ if got := configSource (cfg3 , "event_key" ); got != "env (INNGEST_EVENT_KEY)" {
495+ t .Errorf ("expected source 'env (INNGEST_EVENT_KEY)' for event_key from env, got %q" , got )
496+ }
497+ }
0 commit comments