mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-07 16:55:15 -04:00
AB#2098 versioned & strict yaml reading (#157)
This commit is contained in:
parent
7c2d1c3490
commit
135c787001
5 changed files with 134 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue