jx/internal/config/block_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

50 lines
929 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package config
import (
_ "fmt"
"github.com/stretchr/testify/assert"
"log"
"os"
"testing"
"strings"
)
var TempDir string
func TestMain(m *testing.M) {
var err error
TempDir, err = os.MkdirTemp("", "testconfig")
if err != nil || TempDir == "" {
log.Fatal(err)
}
rc := m.Run()
os.RemoveAll(TempDir)
os.Exit(rc)
}
func TestNewBlock(t *testing.T) {
configYaml := `
name: "foo"
values:
http_user: "test"
http_pass: "password"
`
docReader := strings.NewReader(configYaml)
block := NewBlock()
assert.NotNil(t, block)
assert.Nil(t, block.Load(docReader))
assert.Equal(t, "foo", block.Name)
val, err := block.GetValue("http_user")
assert.Nil(t, err)
assert.Equal(t, "test", val)
missingVal, missingErr := block.GetValue("content")
assert.ErrorIs(t, missingErr, ErrUnknownConfigurationKey)
assert.Nil(t, missingVal)
}