Skip to content

Commit f5a5279

Browse files
test: Refactor SortBy unmarshal test like #4323
Use the testJSONUnmarshalOnly helper for the success case of TestProjectV2ViewSortBy_UnmarshalJSON instead of unmarshaling by hand and asserting field by field, matching the style introduced in #4323. The error-case subtests stay manual since the helper expects a successful unmarshal.
1 parent d3a1a5e commit f5a5279

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

github/projects_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"fmt"
1212
"net/http"
1313
"testing"
14-
"time"
1514

1615
"github.com/google/go-cmp/cmp"
1716
)
@@ -1753,19 +1752,11 @@ func TestProjectV2ViewSortBy_UnmarshalJSON(t *testing.T) {
17531752
t.Parallel()
17541753
// The second element uses a string field_id, which the OpenAPI schema
17551754
// permits. The first exceeds 2^53 to confirm int64 (not float64) decoding.
1756-
var got []*ProjectV2ViewSortBy
1757-
if err := json.Unmarshal([]byte(`[[9007199254740993,"asc"],["456","desc"]]`), &got); err != nil {
1758-
t.Fatalf("Unmarshal returned error: %v", err)
1759-
}
1760-
if len(got) != 2 {
1761-
t.Fatalf("len(got) = %d, want 2", len(got))
1762-
}
1763-
if got[0].GetFieldID() != 9007199254740993 || got[0].GetDirection() != "asc" {
1764-
t.Errorf("got[0] = %+v, want {9007199254740993 asc}", got[0])
1765-
}
1766-
if got[1].GetFieldID() != 456 || got[1].GetDirection() != "desc" {
1767-
t.Errorf("got[1] = %+v, want {456 desc}", got[1])
1755+
want := []*ProjectV2ViewSortBy{
1756+
{FieldID: Ptr(int64(9007199254740993)), Direction: Ptr("asc")},
1757+
{FieldID: Ptr(int64(456)), Direction: Ptr("desc")},
17681758
}
1759+
testJSONUnmarshalOnly(t, want, `[[9007199254740993,"asc"],["456","desc"]]`)
17691760
})
17701761

17711762
t.Run("wrong tuple length is an error", func(t *testing.T) {

0 commit comments

Comments
 (0)