mstdn/ent.Status
parent
11de44e7dc
commit
5b28f7c14e
|
@ -3,14 +3,13 @@ package ent
|
||||||
import (
|
import (
|
||||||
gojson "encoding/json"
|
gojson "encoding/json"
|
||||||
|
|
||||||
"github.com/reiver/go-json"
|
|
||||||
"github.com/reiver/go-jsonint"
|
"github.com/reiver/go-jsonint"
|
||||||
"github.com/reiver/go-opt"
|
"github.com/reiver/go-opt"
|
||||||
"github.com/reiver/go-nul"
|
"github.com/reiver/go-nul"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
ID opt.Optional[string] `json:"id"`
|
ID opt.Optional[string] `json:"id,omitempty"`
|
||||||
URI nul.Nullable[string] `json:"uri,omitempty"`
|
URI nul.Nullable[string] `json:"uri,omitempty"`
|
||||||
URL nul.Nullable[string] `json:"url,omitempty"`
|
URL nul.Nullable[string] `json:"url,omitempty"`
|
||||||
CreatedAt opt.Optional[string] `json:"created_at,omitempty"`
|
CreatedAt opt.Optional[string] `json:"created_at,omitempty"`
|
||||||
|
@ -42,7 +41,3 @@ type Status struct {
|
||||||
Pinned opt.Optional[bool] `json:"pinned,omitempty"`
|
Pinned opt.Optional[bool] `json:"pinned,omitempty"`
|
||||||
Filtered gojson.RawMessage `json:"filtered,omitempty"`
|
Filtered gojson.RawMessage `json:"filtered,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *Status) MarshalJSON() ([]byte, error) {
|
|
||||||
return json.Marshal(*receiver)
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,8 +3,9 @@ package ent
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"encoding/json"
|
gojson "encoding/json"
|
||||||
|
|
||||||
|
"github.com/reiver/go-json"
|
||||||
"github.com/reiver/go-nul"
|
"github.com/reiver/go-nul"
|
||||||
"github.com/reiver/go-opt"
|
"github.com/reiver/go-opt"
|
||||||
)
|
)
|
||||||
|
@ -164,7 +165,7 @@ func TestStatus_JSON(t *testing.T) {
|
||||||
{
|
{
|
||||||
Status:Status{
|
Status:Status{
|
||||||
ID: opt.Something("123"),
|
ID: opt.Something("123"),
|
||||||
Filtered: json.RawMessage([]byte(`{"once":1,"twice":2,"thrice":3,"fource":4}`)),
|
Filtered: gojson.RawMessage([]byte(`{"once":1,"twice":2,"thrice":3,"fource":4}`)),
|
||||||
},
|
},
|
||||||
Expected: `{"id":"123","filtered":{"once":1,"twice":2,"thrice":3,"fource":4}}`,
|
Expected: `{"id":"123","filtered":{"once":1,"twice":2,"thrice":3,"fource":4}}`,
|
||||||
},
|
},
|
||||||
|
@ -172,7 +173,7 @@ func TestStatus_JSON(t *testing.T) {
|
||||||
|
|
||||||
for testNumber, test := range tests {
|
for testNumber, test := range tests {
|
||||||
|
|
||||||
actualBytes, err := json.Marshal(&test.Status)
|
actualBytes, err := json.Marshal(test.Status)
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
t.Errorf("For test #%d, did not expect to get an error but actually did.", testNumber)
|
t.Errorf("For test #%d, did not expect to get an error but actually did.", testNumber)
|
||||||
|
|
Loading…
Reference in New Issue