50 lines
929 B
Go
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)
|
||
|
}
|