44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package folio
|
|
|
|
import (
|
|
_ "fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"strings"
|
|
"decl/internal/data"
|
|
"decl/internal/codec"
|
|
"io"
|
|
"log/slog"
|
|
)
|
|
|
|
func TestNewBlock(t *testing.T) {
|
|
configYaml := `
|
|
name: "foo"
|
|
values:
|
|
http_user: "test"
|
|
http_pass: "password"
|
|
`
|
|
docReader := strings.NewReader(configYaml)
|
|
|
|
block := NewBlock()
|
|
block.ConfigurationTypes = TestConfigurationTypes
|
|
slog.Info("TestNewBlock()", "block", block, "types", block.ConfigurationTypes)
|
|
|
|
assert.NotNil(t, block)
|
|
assert.Nil(t, block.LoadReader(io.NopCloser(docReader), codec.FormatYaml))
|
|
|
|
assert.Equal(t, "foo", block.Name)
|
|
|
|
block.Values.(*MockQuuz).InjectGetValue = func(key string) (any, error) { return "test", nil }
|
|
val, err := block.GetValue("http_user")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "test", val)
|
|
|
|
block.Values.(*MockQuuz).InjectGetValue = func(key string) (any, error) { return nil, data.ErrUnknownConfigurationKey }
|
|
missingVal, missingErr := block.GetValue("content")
|
|
assert.ErrorIs(t, missingErr, data.ErrUnknownConfigurationKey)
|
|
assert.Nil(t, missingVal)
|
|
}
|