Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 11:16:11 +01:00

Merge branch 'forgejo-federated-star' of codeberg.org:meissa/forgejo into forgejo-federated-star

This commit is contained in:
Michael Jerger 2024-05-01 15:02:36 +02:00
commit 87036ec719

View file

@ -6,6 +6,7 @@ package forgefed
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"testing" "testing"
"time" "time"
@ -93,23 +94,25 @@ func Test_LikeUnmarshalJSON(t *testing.T) {
Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"), Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"),
}, },
}, },
wantErr: nil,
}, },
"wrong": { "invalid": { // ToDo: Here we are testing if the json parser detects invalid json, we could keep this test in case we bould our own.
item: []byte(`{"type":"Wrong","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`), item: []byte(`{"type":"Invalid","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"`),
wantErr: fmt.Errorf("an other error"), want: &ForgeLike{},
wantErr: fmt.Errorf("cannot parse JSON:"),
}, },
} }
for name, tt := range tests { for name, test := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
got := new(ForgeLike) got := new(ForgeLike)
err := got.UnmarshalJSON(tt.item) err := got.UnmarshalJSON(test.item)
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() { if (err != nil || test.wantErr != nil) && !strings.Contains(err.Error(), test.wantErr.Error()) {
t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr) t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, test.wantErr)
return return
} }
if !reflect.DeepEqual(got, tt.want) { if !reflect.DeepEqual(got, test.want) {
t.Errorf("UnmarshalJSON() got = %q, want %q, err %q", got, tt.want, err.Error()) t.Errorf("UnmarshalJSON() got = %q, want %q, err %q", got, test.want, err.Error())
} }
}) })
} }