| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package mcpgodebug |
| 6 |
|
| 7 |
import ( |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/google/go-cmp/cmp" |
| 11 |
) |
| 12 |
|
| 13 |
func TestParseCompatibility_Success(t *testing.T) { |
| 14 |
tests := []struct { |
| 15 |
name string |
| 16 |
envVal string |
| 17 |
want map[string]string |
| 18 |
}{ |
| 19 |
{ |
| 20 |
name: "Basic", |
| 21 |
envVal: "foo=bar,baz=qux", |
| 22 |
want: map[string]string{ |
| 23 |
"foo": "bar", |
| 24 |
"baz": "qux", |
| 25 |
}, |
| 26 |
}, |
| 27 |
{ |
| 28 |
name: "Empty", |
| 29 |
envVal: "", |
| 30 |
want: nil, |
| 31 |
}, |
| 32 |
{ |
| 33 |
name: "WithWhitespace", |
| 34 |
envVal: " foo = bar \t, baz = qux ", |
| 35 |
want: map[string]string{ |
| 36 |
"foo": "bar", |
| 37 |
"baz": "qux", |
| 38 |
}, |
| 39 |
}, |
| 40 |
{ |
| 41 |
name: "WithEqualsSignInValue", |
| 42 |
envVal: "foo=bar=baz", |
| 43 |
want: map[string]string{ |
| 44 |
"foo": "bar=baz", |
| 45 |
}, |
| 46 |
}, |
| 47 |
} |
| 48 |
for _, tt := range tests { |
| 49 |
t.Run(tt.name, func(t *testing.T) { |
| 50 |
got, err := parseCompatibility(tt.envVal) |
| 51 |
if err != nil { |
| 52 |
t.Fatalf("parseCompatibility() failed: %v", err) |
| 53 |
} |
| 54 |
if diff := cmp.Diff(tt.want, got); diff != "" { |
| 55 |
t.Errorf("parseCompatibility() mismatch (-want +got):\n%s", diff) |
| 56 |
} |
| 57 |
}) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
func TestParseCompatibility_Failure(t *testing.T) { |
| 62 |
tests := []struct { |
| 63 |
name string |
| 64 |
envVal string |
| 65 |
}{ |
| 66 |
{ |
| 67 |
name: "NoEqualsSign", |
| 68 |
envVal: "invalidformat", |
| 69 |
}, |
| 70 |
{ |
| 71 |
name: "MixedValidAndInvalid", |
| 72 |
envVal: "foo=bar,baz", |
| 73 |
}, |
| 74 |
{ |
| 75 |
name: "EmptyPart", |
| 76 |
envVal: "foo=bar,,baz=qux", |
| 77 |
}, |
| 78 |
} |
| 79 |
|
| 80 |
for _, tt := range tests { |
| 81 |
t.Run(tt.name, func(t *testing.T) { |
| 82 |
_, err := parseCompatibility(tt.envVal) |
| 83 |
if err == nil { |
| 84 |
t.Error("parseCompatibility() expected error, got nil") |
| 85 |
} |
| 86 |
}) |
| 87 |
} |
| 88 |
} |