Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-29 21:26:10 +01:00
forgejo/models/activitypub/actor_test.go
2024-02-10 15:09:23 +01:00

79 lines
1.6 KiB
Go

// Copyright 2023 The forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package activitypub
import (
"testing"
)
func TestActorParserEmpty(t *testing.T) {
item := ""
want := ActorID{}
got, _ := ParseActorID(item)
if got != want {
t.Errorf("ParseActorID returned non empty actor id for empty input.")
}
}
func TestActorParserValid(t *testing.T) {
item := "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"
want := ActorID{
schema: "https",
userId: "1",
path: "/api/v1/activitypub/user-id/1",
host: "repo.prod.meissa.de",
port: "",
}
got, _ := ParseActorID(item)
if got != want {
t.Errorf("ParseActorID did not return want: %v.", want)
}
}
func TestValidateValid(t *testing.T) {
item := ActorID{
schema: "https",
userId: "1",
path: "/api/v1/activitypub/user-id/1",
host: "repo.prod.meissa.de",
port: "",
}
if err := item.Validate(); err != nil {
t.Errorf("Validating actor returned non nil with valid input.")
}
}
func TestValidateInvalid(t *testing.T) {
item := "123456"
actor, _ := ParseActorID(item)
if err := actor.Validate(); err == nil {
t.Errorf("Validating actor returned nil with false input.")
}
}
func TestGetHostAndPort(t *testing.T) {
item := ActorID{
schema: "https",
userId: "1",
path: "/api/v1/activitypub/user-id/1",
host: "repo.prod.meissa.de",
port: "80",
}
want := "repo.prod.meissa.de:80"
hostAndPort := item.GetHostAndPort()
if hostAndPort != want {
t.Errorf("GetHostAndPort did not return correct host and port combination: %v", hostAndPort)
}
}