MCPcopy Create free account
hub / github.com/github/gh-aw / TestExtractEngineConfigFromJSON

Function TestExtractEngineConfigFromJSON

pkg/workflow/engine_includes_test.go:547–641  ·  view source on GitHub ↗

TestExtractEngineConfigFromJSON tests the extractEngineConfigFromJSON function

(t *testing.T)

Source from the content-addressed store, hash-verified

545
546// TestExtractEngineConfigFromJSON tests the extractEngineConfigFromJSON function
547func TestExtractEngineConfigFromJSON(t *testing.T) {
548 compiler := NewCompiler()
549
550 tests := []struct {
551 name string
552 engineJSON string
553 expectedID string
554 expectedEnv map[string]string
555 expectError bool
556 }{
557 {
558 name: "simple string engine",
559 engineJSON: `"claude"`,
560 expectedID: "claude",
561 expectError: false,
562 },
563 {
564 name: "object with id only",
565 engineJSON: `{"id": "codex"}`,
566 expectedID: "codex",
567 expectError: false,
568 },
569 {
570 name: "codex engine with env vars",
571 engineJSON: `{"id": "codex", "env": {"VAR1": "value1", "VAR2": "value2"}}`,
572 expectedID: "codex",
573 expectedEnv: map[string]string{"VAR1": "value1", "VAR2": "value2"},
574 expectError: false,
575 },
576 {
577 name: "codex engine with non-string scalar env vars",
578 engineJSON: `{"id": "codex", "env": {"STRING_VAR": "value1", "INT_VAR": 1, "FLOAT_VAR": 1000, "LARGE_FLOAT_VAR": 1000000, "BOOL_VAR": true}}`,
579 expectedID: "codex",
580 expectedEnv: map[string]string{"STRING_VAR": "value1", "INT_VAR": "1", "FLOAT_VAR": "1000", "LARGE_FLOAT_VAR": "1000000", "BOOL_VAR": "true"},
581 expectError: false,
582 },
583 {
584 name: "invalid JSON",
585 engineJSON: `{invalid}`,
586 expectError: true,
587 },
588 {
589 name: "empty string",
590 engineJSON: ``,
591 expectedID: "",
592 expectError: false,
593 },
594 }
595
596 for _, tt := range tests {
597 t.Run(tt.name, func(t *testing.T) {
598 config, err := compiler.extractEngineConfigFromJSON(tt.engineJSON)
599
600 if tt.expectError {
601 if err == nil {
602 t.Error("Expected error but got none")
603 }
604 return

Callers

nothing calls this directly

Calls 5

NewCompilerFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected