2023-11-15 17:07:23 +03:00
|
|
|
// Copyright 2023 The forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package activitypub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_ActorParser(t *testing.T) {
|
|
|
|
type testPair struct {
|
2023-11-16 18:03:05 +03:00
|
|
|
item string
|
2023-11-22 15:28:13 +03:00
|
|
|
want ActorID
|
2023-11-15 17:07:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
tests := map[string]testPair{
|
|
|
|
"empty": {
|
|
|
|
item: "",
|
2023-11-22 15:28:13 +03:00
|
|
|
want: ActorID{},
|
2023-11-15 17:07:23 +03:00
|
|
|
},
|
2023-11-16 18:03:05 +03:00
|
|
|
"withValidActorID": {
|
2023-11-15 17:07:23 +03:00
|
|
|
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
2023-11-22 15:28:13 +03:00
|
|
|
want: ActorID{
|
2023-11-16 18:03:05 +03:00
|
|
|
schema: "https",
|
|
|
|
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",
|
2023-11-22 15:28:13 +03:00
|
|
|
want: ActorID{
|
2023-11-16 18:03:05 +03:00
|
|
|
schema: "https",
|
2023-11-15 17:07:23 +03:00
|
|
|
userId: "1",
|
2023-11-16 18:03:05 +03:00
|
|
|
path: "/api/v1/activitypub/user-id/1",
|
2023-11-15 17:07:23 +03:00
|
|
|
host: "repo.prod.meissa.de",
|
|
|
|
port: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-11-16 18:03:05 +03:00
|
|
|
for name, _ := range tests {
|
2023-11-15 17:07:23 +03:00
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-11-22 15:28:13 +03:00
|
|
|
_, err := ParseActorID(tests[name].item)
|
2023-11-15 17:07:23 +03:00
|
|
|
|
2023-11-16 18:03:05 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("parseActor() error = \"%v\"", err)
|
2023-11-15 17:07:23 +03:00
|
|
|
return
|
|
|
|
}
|
2023-11-16 18:03:05 +03:00
|
|
|
|
2023-11-15 17:07:23 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|