Skip to content
Snippets Groups Projects
mytoken_test.go 752 B
Newer Older
package mytokenrepo
Gabriel Zachmann's avatar
Gabriel Zachmann committed
import (
	"testing"

	"github.com/oidc-mytoken/server/shared/mytoken/pkg/mtid"
Gabriel Zachmann's avatar
Gabriel Zachmann committed
)
func testRoot(t *testing.T, a MytokenEntry, expected bool) {
	root := a.Root()
	if root != expected {
		if expected {
			t.Errorf("Actually '%+v' is a root entry", a)
		} else {
			t.Errorf("Actually '%+v' is not a root entry", a)
		}
	}
}

func TestSuperTokenEntry_RootEmpty(t *testing.T) {
	a := MytokenEntry{}
	testRoot(t, a, true)
}
func TestSuperTokenEntry_RootHasParentAsRoot(t *testing.T) {
	id := mtid.New()
	a := MytokenEntry{ParentID: id, RootID: id}
	testRoot(t, a, false)
}
func TestSuperTokenEntry_RootHasRoot(t *testing.T) {
	pid := mtid.New()
	rid := mtid.New()
	a := MytokenEntry{ParentID: pid, RootID: rid}
	testRoot(t, a, false)
}