54 lines
988 B
Go
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)
|
|
}
|