mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-13 05:11:20 +01:00
star: test first
This commit is contained in:
parent
1044e44ee5
commit
a1885a5767
1 changed files with 57 additions and 0 deletions
57
modules/forgefed/star_test.go
Normal file
57
modules/forgefed/star_test.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package forgefed
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
ap "github.com/go-ap/activitypub"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_StarMarshalJSON(t *testing.T) {
|
||||||
|
type testPair struct {
|
||||||
|
item Star
|
||||||
|
want []byte
|
||||||
|
wantErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := map[string]testPair{
|
||||||
|
"empty": {
|
||||||
|
item: Star{},
|
||||||
|
want: nil,
|
||||||
|
},
|
||||||
|
"with ID": {
|
||||||
|
item: Star{
|
||||||
|
Source: "forgejo",
|
||||||
|
Activity: ap.Activity{
|
||||||
|
ID: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||||
|
Type: "Star",
|
||||||
|
Object: ap.Object{
|
||||||
|
ID: "https://codeberg.org/api/activitypub/repository-id/1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []byte(`{
|
||||||
|
"type": "Star",
|
||||||
|
"source": "forgejo",
|
||||||
|
"actor": "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||||
|
"object": "https://codeberg.org/api/activitypub/repository-id/1"
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, tt := range tests {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
got, err := tt.item.MarshalJSON()
|
||||||
|
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
|
||||||
|
t.Errorf("MarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("MarshalJSON() got = %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue