59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package identity
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
)
|
|
|
|
|
|
func setupIdentifier() Identifier {
|
|
root := NewRoot("sys")
|
|
return New(root, "test")
|
|
}
|
|
|
|
func TestNewIdentifier(t *testing.T) {
|
|
i := setupIdentifier()
|
|
if i == nil {
|
|
t.Errorf("Failed creating new identifier")
|
|
}
|
|
}
|
|
|
|
func TestNewChildIdentifier(t *testing.T) {
|
|
i := setupIdentifier()
|
|
c := i.CreateChild("newchild")
|
|
a := c.Address()
|
|
if a != i.Address() + "/newchild" {
|
|
t.Errorf("CreateChild() failed creating new child identifier: %s", a)
|
|
}
|
|
}
|
|
|
|
func TestIdentifierAddress(t *testing.T) {
|
|
i := setupIdentifier()
|
|
a := i.Address()
|
|
u,e := url.Parse(a)
|
|
if e != nil {
|
|
t.Errorf("Failed parsing identifier address %s", e)
|
|
}
|
|
if u.Scheme != "feudal" {
|
|
t.Errorf("Invalid identifier address scheme %s", u.Scheme)
|
|
}
|
|
}
|
|
|
|
func TestIdentifierParent(t *testing.T) {
|
|
i := setupIdentifier()
|
|
c := i.CreateChild("task")
|
|
u,e := url.Parse(c.Parent().Address())
|
|
if e != nil || u.Path != "/test" {
|
|
t.Errorf("Parent() returned incorrect path %s %s", u.Path, e)
|
|
}
|
|
}
|
|
|
|
func TestNewFromAddress(t *testing.T) {
|
|
i := NewFromAddress("feudal://test@hostfoo/workerbar")
|
|
if i.Hostname() != "hostfoo" {
|
|
t.Errorf("Failed generating identifier from url - hostname mismatch")
|
|
}
|
|
}
|