mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Create easier to read tests for parser and validator
This commit is contained in:
parent
62eae6564f
commit
ad8adc880f
1 changed files with 47 additions and 41 deletions
|
@ -7,48 +7,54 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_ActorParser(t *testing.T) {
|
func TestActorParserEmpty(t *testing.T) {
|
||||||
type testPair struct {
|
item := ""
|
||||||
item string
|
want := ActorID{}
|
||||||
want ActorID
|
|
||||||
|
got, _ := ParseActorID(item)
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("ParseActorID returned non empty actor id for empty input.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := map[string]testPair{
|
func TestActorParserValid(t *testing.T) {
|
||||||
"empty": {
|
item := "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"
|
||||||
item: "",
|
want := ActorID{
|
||||||
want: ActorID{},
|
|
||||||
},
|
|
||||||
"withValidActorID": {
|
|
||||||
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
|
||||||
want: ActorID{
|
|
||||||
schema: "https",
|
schema: "https",
|
||||||
userId: "1",
|
userId: "1",
|
||||||
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: "",
|
||||||
},
|
}
|
||||||
},
|
|
||||||
"withInvalidActorID": {
|
got, _ := ParseActorID(item)
|
||||||
item: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
|
||||||
want: ActorID{
|
if got != want {
|
||||||
|
t.Errorf("Test Fail: ParseActorID did not return want: %v.", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateValid(t *testing.T) {
|
||||||
|
item := ActorID{
|
||||||
schema: "https",
|
schema: "https",
|
||||||
userId: "1",
|
userId: "1",
|
||||||
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: "",
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, _ := range tests {
|
if err := item.Validate(); err != nil {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Errorf("Test Fail: Validating actor returned non nil with valid input.")
|
||||||
_, err := ParseActorID(tests[name].item)
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("parseActor() error = \"%v\"", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
func TestValidateInvalid(t *testing.T) {
|
||||||
|
item := "123456"
|
||||||
|
|
||||||
|
actor, _ := ParseActorID(item)
|
||||||
|
|
||||||
|
if err := actor.Validate(); err == nil {
|
||||||
|
t.Errorf("Test Fail: Validating actor returned nil with false input.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue