mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-11-11 16:25:05 -05:00
config: improve usage and meaning of validate (#1975)
* discuss miniup config.Default() usage + discourage usage for Default() in comment * Update internal/config/config_test.go Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com> * add enterprise version check for config.Default * split config comment lines * daniel feedback * featureset.CanUseEmbeddedMeasurmentsAndImage --------- Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
This commit is contained in:
parent
1edbe962c1
commit
161bb37cba
6 changed files with 43 additions and 17 deletions
|
|
@ -298,6 +298,7 @@ type AttestationConfig struct {
|
|||
}
|
||||
|
||||
// Default returns a struct with the default config.
|
||||
// IMPORTANT: Ensure that any state mutation is followed by a call to Validate() to ensure that the config is always in a valid state. Avoid usage outside of tests.
|
||||
func Default() *Config {
|
||||
return &Config{
|
||||
Version: Version3,
|
||||
|
|
@ -367,6 +368,19 @@ func Default() *Config {
|
|||
}
|
||||
}
|
||||
|
||||
// MiniDefault returns a default config for a mini cluster.
|
||||
func MiniDefault() (*Config, error) {
|
||||
config := Default()
|
||||
config.Name = constants.MiniConstellationUID
|
||||
config.RemoveProviderAndAttestationExcept(cloudprovider.QEMU)
|
||||
config.StateDiskSizeGB = 8
|
||||
// only release images (e.g. v2.7.0) use the production NVRAM
|
||||
if !config.IsReleaseImage() {
|
||||
config.Provider.QEMU.NVRAM = "testing"
|
||||
}
|
||||
return config, config.Validate(false)
|
||||
}
|
||||
|
||||
// fromFile returns config file with `name` read from `fileHandler` by parsing
|
||||
// it as YAML. You should prefer config.New to read env vars and validate
|
||||
// config in a consistent manner.
|
||||
|
|
|
|||
|
|
@ -376,6 +376,15 @@ func TestValidate(t *testing.T) {
|
|||
return cnf
|
||||
}(),
|
||||
},
|
||||
"miniup default config is not valid because image and measurements are missing in OSS": {
|
||||
cnf: func() *Config {
|
||||
config, _ := MiniDefault()
|
||||
require.NotNil(t, config)
|
||||
return config
|
||||
}(),
|
||||
wantErr: true,
|
||||
wantErrCount: 2,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -389,7 +398,7 @@ func TestValidate(t *testing.T) {
|
|||
assert.Error(err)
|
||||
var valErr *ValidationError
|
||||
require.ErrorAs(err, &valErr)
|
||||
assert.Equal(tc.wantErrCount, valErr.messagesCount())
|
||||
assert.Equalf(tc.wantErrCount, valErr.messagesCount(), "Got unexpected error count: %d: %s", valErr.messagesCount(), valErr.LongMessage())
|
||||
return
|
||||
}
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue