This repository has been archived on 2022-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
activitypub/encoding_gob_test.go
2021-03-14 19:40:36 +01:00

48 lines
926 B
Go

package activitypub
import (
"bytes"
"encoding/gob"
"reflect"
"testing"
)
func TestMarshalGob(t *testing.T) {
tests := []struct {
name string
it Item
want []byte
wantErr bool
}{
{
name: "empty object",
it: &Object{
ID: "test",
},
want: []byte{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
//got, err := MarshalGob(tt.it)
buf := bytes.NewBuffer(make([]byte,0))
err := gob.NewEncoder(buf).Encode(tt.it)
got := buf.Bytes()
it := new(Object)
gob.NewDecoder(bytes.NewReader(got)).Decode(it)
if it.ID == tt.it.GetID() {
t.Logf("Yay!")
}
if (err != nil) != tt.wantErr {
t.Errorf("MarshalGob() error = %s, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
t.Errorf("MarshalGob() got = %#v, want %#v", got, tt.want)
}
})
}
}