jx/internal/folio/registry_test.go
Matthew Rich 04b27dc5df
Some checks failed
Lint / golangci-lint (push) Has been cancelled
Declarative Tests / test (push) Has been cancelled
Declarative Tests / build-fedora (push) Has been cancelled
Declarative Tests / build-ubuntu-focal (push) Has been cancelled
add folio package
2024-08-17 18:19:56 -07:00

55 lines
1.3 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package folio
import (
"github.com/stretchr/testify/assert"
"testing"
"decl/internal/mapper"
"log/slog"
)
// Registry maps documents
// lookup document by uri
// lookup document by declaration
// generate declaration for document/config
func TestNewRegistry(t *testing.T) {
r := NewRegistry()
assert.NotNil(t, r)
r.ResourceTypes = TestResourceTypes
var docs mapper.Getter[*Declaration, *Document] = r
decl := NewDeclaration()
_, notexists := docs.Get(decl)
assert.False(t, notexists)
doc := NewDocument(r)
res, e := doc.NewResource("foo://")
assert.Nil(t, e)
slog.Info("TestNewRegistry", "doc", doc)
assert.Equal(t, doc.ResourceDeclarations[0].Attributes, res)
r.DeclarationMap[doc.ResourceDeclarations[0]] = doc
_, exists := docs.Get(doc.ResourceDeclarations[0])
assert.True(t, exists)
}
func TestRegistryResourceTypes(t *testing.T) {
r := NewRegistry()
assert.NotNil(t, r)
r.ResourceTypes = TestResourceTypes
doc := r.NewDocument("")
assert.NotNil(t, doc)
res, e := doc.NewResource("foo://")
assert.Nil(t, e)
assert.NotNil(t, res)
decl := doc.ResourceDeclarations[0]
assert.Equal(t, decl.Attributes, res)
assert.Equal(t, TypeName("foo"), decl.Type)
mappedDoc, ok := r.DeclarationMap[decl]
assert.True(t, ok)
assert.Equal(t, doc, mappedDoc)
}