forgejo/models/activitypub/actor_test.go

55 lines
1 KiB
Go
Raw Normal View History

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