jx/internal/builtin/builtin_test.go
Matthew Rich d815419c7b
Some checks failed
Lint / golangci-lint (push) Failing after 10m28s
Declarative Tests / test (push) Failing after 12s
Declarative Tests / build-fedora (push) Failing after 1m57s
Declarative Tests / build-ubuntu-focal (push) Successful in 1m50s
remove duplicate tempdir pkg
2024-09-27 03:18:13 +00:00

60 lines
1.3 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package builtin
import (
"github.com/stretchr/testify/assert"
"log/slog"
"os"
"testing"
"decl/internal/tempdir"
"decl/internal/folio"
"errors"
)
var TempDir tempdir.Path = "testbuiltin"
func TestMain(m *testing.M) {
err := TempDir.Create()
if err != nil || TempDir == "" {
slog.Error("Failed creating temp dir", "error", err)
}
rc := m.Run()
TempDir.Remove()
os.Exit(rc)
}
func TestBuiltInLoad(t *testing.T) {
docs, err := Load("file://documents/facter.jx.yaml")
if ! errors.Is(err, os.ErrNotExist) {
assert.Nil(t, err)
assert.Greater(t, len(docs), 0)
}
}
func TestBuiltInDocuments(t *testing.T) {
docs, err := BuiltInDocuments()
assert.Greater(t, len(docs), 0)
if ! errors.Is(err, os.ErrNotExist) {
assert.Nil(t, err)
config, ok := folio.DocumentRegistry.GetDocument("file://documents/facter.jx.yaml")
assert.True(t, ok)
slog.Info("TestBuiltInDocuments()", "docuemnt", config)
assert.True(t, config.HasConfig("facts"))
c := config.GetConfig("facts")
v, e := c.GetValue("virtual")
assert.Nil(t, e)
assert.Equal(t, "physical", v)
}
systemConfig, systemExists := folio.DocumentRegistry.GetDocument("file://documents/system.jx.yaml")
assert.True(t, systemExists)
assert.True(t, systemConfig.HasConfig("system"))
}