1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-28 09:21:13 -05:00

Fix tests

This commit is contained in:
erik 2023-11-24 13:23:03 +01:00 committed by Michael Jerger
parent 6284355e1e
commit 9568eab62a

View file

@ -5,13 +5,34 @@ package activitypub
import ( import (
"testing" "testing"
"code.gitea.io/gitea/modules/forgefed"
ap "github.com/go-ap/activitypub"
) )
var emptyMockStar *forgefed.Star = &forgefed.Star{
Source: "",
Activity: ap.Activity{
Actor: ap.IRI(""),
Type: "Star",
Object: ap.IRI(""),
},
}
var mockStar *forgefed.Star = &forgefed.Star{
Source: "forgejo",
Activity: ap.Activity{
Actor: ap.IRI("https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"),
Type: "Star",
Object: ap.IRI("https://codeberg.org/api/v1/activitypub/repository-id/1"),
},
}
func TestActorParserEmpty(t *testing.T) { func TestActorParserEmpty(t *testing.T) {
item := "" item := emptyMockStar
want := ActorID{} want := ActorID{}
got, _ := ParseActorID(item) got, _ := ParseActorFromStarActivity(item)
if got != want { if got != want {
t.Errorf("ParseActorID returned non empty actor id for empty input.") t.Errorf("ParseActorID returned non empty actor id for empty input.")
@ -19,26 +40,28 @@ func TestActorParserEmpty(t *testing.T) {
} }
func TestActorParserValid(t *testing.T) { func TestActorParserValid(t *testing.T) {
item := "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1" item := mockStar
want := ActorID{ want := ActorID{
schema: "https",
userId: "1", userId: "1",
source: "forgejo",
schema: "https",
path: "/api/v1/activitypub/user-id/1", path: "/api/v1/activitypub/user-id/1",
host: "repo.prod.meissa.de", host: "repo.prod.meissa.de",
port: "", port: "",
} }
got, _ := ParseActorID(item) got, _ := ParseActorFromStarActivity(item)
if got != want { if got != want {
t.Errorf("ParseActorID did not return want: %v.", want) t.Errorf("\nParseActorID did not return want: %v\n but %v", want, got)
} }
} }
func TestValidateValid(t *testing.T) { func TestValidateValid(t *testing.T) {
item := ActorID{ item := ActorID{
schema: "https",
userId: "1", userId: "1",
source: "forgejo",
schema: "https",
path: "/api/v1/activitypub/user-id/1", path: "/api/v1/activitypub/user-id/1",
host: "repo.prod.meissa.de", host: "repo.prod.meissa.de",
port: "", port: "",
@ -50,9 +73,9 @@ func TestValidateValid(t *testing.T) {
} }
func TestValidateInvalid(t *testing.T) { func TestValidateInvalid(t *testing.T) {
item := "123456" item := emptyMockStar
actor, _ := ParseActorID(item) actor, _ := ParseActorFromStarActivity(item)
if valid, _ := actor.IsValid(); valid { if valid, _ := actor.IsValid(); valid {
t.Errorf("Actor was valid with invalid input.") t.Errorf("Actor was valid with invalid input.")