Strip / from IRI path if last character
This commit is contained in:
parent
db9606f596
commit
6ff39cfc8d
2 changed files with 52 additions and 5 deletions
4
typer.go
4
typer.go
|
@ -115,6 +115,10 @@ func (t CollectionTypes) Split(i pub.IRI) (pub.IRI, CollectionType) {
|
|||
|
||||
// IRIf formats an IRI from an existing IRI and the collection type
|
||||
func IRIf(i pub.IRI, t CollectionType) pub.IRI {
|
||||
onePastLast := len(i)
|
||||
if i[onePastLast-1] == '/' {
|
||||
i = i[:onePastLast-1]
|
||||
}
|
||||
return pub.IRI(fmt.Sprintf("%s/%s", i, t))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package handlers
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"github.com/go-ap/activitypub"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPathTyper_Type(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
|
@ -22,10 +25,6 @@ func TestValidCollectionIRI(t *testing.T) {
|
|||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestIRIf(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestSplit(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
@ -45,3 +44,47 @@ func TestCollectionType_OfActor(t *testing.T) {
|
|||
func TestCollectionTypes_Contains(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestIRIf(t *testing.T) {
|
||||
type args struct {
|
||||
i activitypub.IRI
|
||||
t CollectionType
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want activitypub.IRI
|
||||
}{
|
||||
{
|
||||
name: "plain concat",
|
||||
args: args{
|
||||
i: "https://example.com",
|
||||
t: "inbox",
|
||||
},
|
||||
want: "https://example.com/inbox",
|
||||
},
|
||||
{
|
||||
name: "strip root from iri",
|
||||
args: args{
|
||||
i: "https://example.com/",
|
||||
t: "inbox",
|
||||
},
|
||||
want: "https://example.com/inbox",
|
||||
},
|
||||
{
|
||||
name: "invalid iri",
|
||||
args: args{
|
||||
i: "example.com",
|
||||
t: "test",
|
||||
},
|
||||
want: "example.com/test",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IRIf(tt.args.i, tt.args.t); got != tt.want {
|
||||
t.Errorf("IRIf() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue