internal/mcp: remove omitzero
To be compatible with Go 1.23, we cannot use the encoding/json "omitzero" option. Replace with a custom MarshalJSON method. Change-Id: Ied615ea04fb20e2459f9ed20ef03c81edbc74961 Reviewed-on: https://go-review.googlesource.com/c/tools/+/672417 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
dac5be2c50
commit
aedbba98ee
1 changed files with 73 additions and 3 deletions
|
|
@ -57,3 +57,46 @@ func TestContent(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceContents(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
rc mcp.ResourceContents
|
||||
want string // marshaled JSON
|
||||
}{
|
||||
{
|
||||
mcp.ResourceContents{URI: "u", Text: "t"},
|
||||
`{"uri":"u","text":"t"}`,
|
||||
},
|
||||
{
|
||||
mcp.ResourceContents{URI: "u", MIMEType: "m", Text: "t"},
|
||||
`{"uri":"u","mimeType":"m","text":"t"}`,
|
||||
},
|
||||
{
|
||||
mcp.ResourceContents{URI: "u", Text: "", Blob: nil},
|
||||
`{"uri":"u","text":""}`,
|
||||
},
|
||||
{
|
||||
mcp.ResourceContents{URI: "u", Blob: []byte{}},
|
||||
`{"uri":"u","blob":""}`,
|
||||
},
|
||||
{
|
||||
mcp.ResourceContents{URI: "u", Blob: []byte{1}},
|
||||
`{"uri":"u","blob":"AQ=="}`,
|
||||
},
|
||||
} {
|
||||
data, err := json.Marshal(tt.rc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := string(data); got != tt.want {
|
||||
t.Errorf("%#v:\ngot %s\nwant %s", tt.rc, got, tt.want)
|
||||
}
|
||||
var urc mcp.ResourceContents
|
||||
if err := json.Unmarshal(data, &urc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(tt.rc, urc); diff != "" {
|
||||
t.Errorf("mismatch (-want, +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue