Skip to content
Snippets Groups Projects
mytoken_test.go 876 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
)
Gabriel Zachmann's avatar
Gabriel Zachmann committed
func TestMytokenEntry_Root(t *testing.T) {
	parentRoot := mtid.New()
	tests := []struct {
		name     string
		mt       MytokenEntry
		expected bool
	}{
		{
			name:     "Empty",
			mt:       MytokenEntry{},
			expected: true,
		},
		{
			name: "HasParentAsRoot",
			mt: MytokenEntry{
				ParentID: parentRoot,
			},
			expected: false,
		},
		{
			name: "HasParentAndRoot",
			mt: MytokenEntry{
				ParentID: mtid.New(),
			},
			expected: false,
		},
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	for _, test := range tests {
		t.Run(
			test.name, func(t *testing.T) {
				root := test.mt.Root()
				if root != test.expected {
					if test.expected {
						t.Errorf("Actually '%+v' is a root entry", test.mt)
					} else {
						t.Errorf("Actually '%+v' is not a root entry", test.mt)
					}
				}
			},
		)
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	}