Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions pkg/mcp/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,63 @@ func TestWithPrefix_Validation(t *testing.T) {
})
}
}

// TestAppendBoolFlag verifies that appendBoolFlag handles nil, true, and false correctly.
func TestAppendBoolFlag(t *testing.T) {
trueVal := true
falseVal := false

cases := []struct {
name string
value *bool
want []string
}{
{"nil omits flag", nil, []string{}},
{"true appends flag", &trueVal, []string{"--push"}},
{"false appends flag=false", &falseVal, []string{"--push=false"}},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := appendBoolFlag(nil, "--push", tc.value)
if len(got) != len(tc.want) {
t.Fatalf("appendBoolFlag(nil, --push, %v) = %v, want %v", tc.value, got, tc.want)
}
for i := range got {
if got[i] != tc.want[i] {
t.Errorf("result[%d] = %q, want %q", i, got[i], tc.want[i])
}
}
})
}
}

// TestAppendStringFlag verifies that appendStringFlag handles nil, empty, and non-empty values.
func TestAppendStringFlag(t *testing.T) {
empty := ""
val := "prod"

cases := []struct {
name string
value *string
want []string
}{
{"nil omits flag", nil, []string{}},
{"empty omits flag", &empty, []string{}},
{"non-empty appends flag and value", &val, []string{"--namespace", "prod"}},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := appendStringFlag(nil, "--namespace", tc.value)
if len(got) != len(tc.want) {
t.Fatalf("appendStringFlag(nil, --namespace, %v) = %v, want %v", tc.value, got, tc.want)
}
for i := range got {
if got[i] != tc.want[i] {
t.Errorf("result[%d] = %q, want %q", i, got[i], tc.want[i])
}
}
})
}
}
12 changes: 8 additions & 4 deletions pkg/mcp/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ func appendStringFlag(args []string, flag string, value *string) []string {
return args
}

// appendBoolFlag adds a boolean flag to args only if the value is non-nil and true.
// This ensures we only pass flags that were explicitly provided by the user.
// appendBoolFlag adds a boolean flag to args only if the value is non-nil.
// When true, appends the flag (e.g. --push). When false, appends
// flag=false (e.g. --push=false) to allow explicit disabling.
func appendBoolFlag(args []string, flag string, value *bool) []string {
if value != nil && *value {
return append(args, flag)
if value != nil {
if *value {
return append(args, flag)
}
return append(args, flag+"=false")
}
return args
}
Expand Down
Loading