jx/internal/folio/block_test.go
Matthew Rich 6e0049c4d2
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add resource and document constraints
2024-09-19 07:57:26 +00:00

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)
}