1
0
Fork 0
golang-github-go-ap-activit.../object_id_test.go
Daniel Baumann c8085bda34
Adding upstream version 0.0~git20250501.71edba4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-05-18 22:06:39 +02:00

110 lines
1.8 KiB
Go

package activitypub
import (
"bytes"
"testing"
)
func TestID_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
data []byte
want ID
}{
{
name: "nil",
data: []byte(nil),
want: "",
},
{
name: "empty",
data: []byte(""),
want: "",
},
{
name: "something",
data: []byte("something"),
want: "something",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ID("")
got.UnmarshalJSON(tt.data)
if got != tt.want {
t.Errorf("UnmarshalJSON() = %v, want %v", got, tt.want)
}
})
}
}
func TestID_MarshalJSON(t *testing.T) {
tests := []struct {
name string
i ID
want []byte
wantErr error
}{
{
name: "nil",
i: "",
want: []byte(nil),
},
{
name: "empty",
i: "",
want: []byte(""),
},
{
name: "something",
i: "something",
want: []byte(`"something"`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.i.MarshalJSON()
if tt.wantErr != nil {
if err == nil {
t.Errorf("MarshalJSON() returned no error but expected %v", tt.wantErr)
}
if tt.wantErr.Error() != err.Error() {
t.Errorf("MarshalJSON() returned error %v but expected %v", err, tt.wantErr)
}
return
}
if !bytes.Equal(got, tt.want) {
t.Errorf("MarshalJSON() = %s, want %s", got, tt.want)
}
})
}
t.Skip("TODO")
}
func TestID_IsValid(t *testing.T) {
tests := []struct {
name string
i ID
want bool
}{
{
name: "empty",
i: "",
want: false,
},
{
name: "something",
i: "something",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.i.IsValid(); got != tt.want {
t.Errorf("IsValid() = %v, want %v", got, tt.want)
}
})
}
}