Skip to content

Commit

Permalink
Increased UT coverage for api/json
Browse files Browse the repository at this point in the history
  • Loading branch information
WilsonRadadia20 committed Jan 31, 2025
1 parent 94fb083 commit 3bf0e46
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/json/json_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,34 @@ func TestTypeFields(t *testing.T) {
}
}
}

func TestMarshalIndent(t *testing.T) {
type TestStruct struct {
Field1 string
Field2 int
Field3 []byte
}

testCases := []struct {
input TestStruct
expected string
opts encOpts
}{
{input: TestStruct{Field1: "test", Field2: 123, Field3: []byte("bytes")}, expected: `{
"Field1": "test",
"Field2": 123,
"Field3": "Ynl0ZXM="
}`, opts: encOpts{quoted: false, escapeHTML: false}},
}

for _, tc := range testCases {
result, err := MarshalIndent(tc.input, "", " ")
if err != nil {
t.Errorf("MarshalIndent(%v) = %v, expected nil", tc.input, err)
}

if string(result) != tc.expected {
t.Errorf("MarshalIndent(%v) = %v, expected %v", tc.input, string(result), tc.expected)
}
}
}

0 comments on commit 3bf0e46

Please sign in to comment.