AB#2098 versioned & strict yaml reading (#157)

This commit is contained in:
Fabian Kammel 2022-05-18 18:10:57 +02:00 committed by GitHub
parent 7c2d1c3490
commit 135c787001
5 changed files with 134 additions and 32 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -211,6 +212,26 @@ func TestReadYAML(t *testing.T) {
}
}
func TestReadYAMLStrictUnknownFieldFails(t *testing.T) {
assert := assert.New(t)
type SampleConfig struct {
Version string `yaml:"version"`
Value string `yaml:"value"`
}
yamlConfig := `
version: "1.0.0"
value: "foobar"
sneakyValue: "superSecret"
`
handler := NewHandler(afero.NewMemMapFs())
assert.NoError(handler.Write(constants.ConfigFilename, []byte(yamlConfig), OptNone))
var readInConfig SampleConfig
assert.Error(handler.ReadYAMLStrict(constants.ConfigFilename, &readInConfig))
}
func TestWriteYAML(t *testing.T) {
type testContent struct {
First string