WIP test for parsing the actor
This commit is contained in:
parent
0c367070af
commit
7193c0bd9b
|
@ -5,13 +5,22 @@ package activitypub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/activitypub"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ActorData struct { // ToDo: is a mock struct a good idea?
|
||||||
|
schema string
|
||||||
|
userId string
|
||||||
|
path string
|
||||||
|
host string
|
||||||
|
port string // optional
|
||||||
|
}
|
||||||
|
|
||||||
func Test_ActorParser(t *testing.T) {
|
func Test_ActorParser(t *testing.T) {
|
||||||
type testPair struct {
|
type testPair struct {
|
||||||
item string
|
item string
|
||||||
want ActorData
|
want ActorData
|
||||||
wantErr error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := map[string]testPair{
|
tests := map[string]testPair{
|
||||||
|
@ -19,25 +28,37 @@ func Test_ActorParser(t *testing.T) {
|
||||||
item: "",
|
item: "",
|
||||||
want: ActorData{},
|
want: ActorData{},
|
||||||
},
|
},
|
||||||
"withActorID": {
|
"withValidActorID": {
|
||||||
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
||||||
want: ActorData{
|
want: ActorData{
|
||||||
schema: "https://",
|
schema: "https",
|
||||||
userId: "1",
|
userId: "1",
|
||||||
|
path: "/api/v1/activitypub/user-id/1",
|
||||||
|
host: "repo.prod.meissa.de",
|
||||||
|
port: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"withInvalidActorID": {
|
||||||
|
item: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||||
|
want: ActorData{
|
||||||
|
schema: "https",
|
||||||
|
userId: "1",
|
||||||
|
path: "/api/v1/activitypub/user-id/1",
|
||||||
host: "repo.prod.meissa.de",
|
host: "repo.prod.meissa.de",
|
||||||
port: "",
|
port: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, tt := range tests {
|
for name, _ := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
_, err := tt.want.parseActor(tests[name].item)
|
_, err := activitypub.ParseActorData(tests[name].item)
|
||||||
|
|
||||||
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
|
if err != nil {
|
||||||
t.Errorf("parseActor() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)
|
t.Errorf("parseActor() error = \"%v\"", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue