jx/internal/folio/block_test.go

44 lines
1.1 KiB
Go
Raw Normal View History

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