jx/internal/config/document_test.go
Matthew Rich 1460d2285b
Some checks failed
Declarative Tests / build-ubuntu-focal (push) Waiting to run
Lint / golangci-lint (push) Failing after 15s
Declarative Tests / test (push) Failing after 5s
Declarative Tests / build-fedora (push) Has been cancelled
add support for configuration documents
2024-07-01 14:54:18 -07:00

54 lines
988 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package config
import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestNewDocument(t *testing.T) {
d := NewDocument()
assert.NotNil(t, d)
}
func TestDocumentLoader(t *testing.T) {
document := `
---
configurations:
- type: generic
name: global
values:
install_dir: /opt/jx
- name: system
values:
dist: ubuntu
release: focal
`
d := NewDocument()
assert.NotNil(t, d)
docReader := strings.NewReader(document)
e := d.Load(docReader)
assert.Nil(t, e)
configurations := d.Configurations()
assert.Equal(t, 2, len(configurations))
b := d.Get("system")
assert.NotNil(t, b)
cfg := b.Configuration()
value, valueErr := cfg.GetValue("dist")
assert.Nil(t, valueErr)
assert.Equal(t, "ubuntu", value)
}
func TestDocumentJSONSchema(t *testing.T) {
document := NewDocument()
document.ConfigBlocks = []Block{}
e := document.Validate()
assert.Nil(t, e)
}