mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-18 20:34:35 -05:00
804c173d52
* Use terraform in CLI to create QEMU cluster * Dont allow qemu creation on os/arch other than linux/amd64 * Allow usage of --name flag for QEMU resources Signed-off-by: Daniel Weiße <dw@edgeless.systems>
127 lines
2.9 KiB
Go
127 lines
2.9 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateConfig(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
cnf *config.Config
|
|
provider cloudprovider.Provider
|
|
wantOutput bool
|
|
wantErr bool
|
|
}{
|
|
"default config is not valid": {
|
|
cnf: config.Default(),
|
|
wantOutput: true,
|
|
wantErr: true,
|
|
},
|
|
"default Azure config is not valid": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
az := cnf.Provider.Azure
|
|
cnf.Provider = config.ProviderConfig{}
|
|
cnf.Provider.Azure = az
|
|
return cnf
|
|
}(),
|
|
provider: cloudprovider.Azure,
|
|
wantOutput: true,
|
|
wantErr: true,
|
|
},
|
|
"Azure config with all required fields is valid": {
|
|
cnf: defaultConfigWithExpectedMeasurements(t, config.Default(), cloudprovider.Azure),
|
|
provider: cloudprovider.Azure,
|
|
},
|
|
"default GCP config is not valid": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
gcp := cnf.Provider.GCP
|
|
cnf.Provider = config.ProviderConfig{}
|
|
cnf.Provider.GCP = gcp
|
|
return cnf
|
|
}(),
|
|
provider: cloudprovider.GCP,
|
|
wantOutput: true,
|
|
wantErr: true,
|
|
},
|
|
"GCP config with all required fields is valid": {
|
|
cnf: defaultConfigWithExpectedMeasurements(t, config.Default(), cloudprovider.GCP),
|
|
provider: cloudprovider.GCP,
|
|
},
|
|
"default QEMU config is not valid": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
qemu := cnf.Provider.QEMU
|
|
cnf.Provider = config.ProviderConfig{}
|
|
cnf.Provider.QEMU = qemu
|
|
return cnf
|
|
}(),
|
|
provider: cloudprovider.QEMU,
|
|
wantOutput: true,
|
|
wantErr: true,
|
|
},
|
|
"QEMU config with all required fields is valid": {
|
|
cnf: defaultConfigWithExpectedMeasurements(t, config.Default(), cloudprovider.QEMU),
|
|
provider: cloudprovider.QEMU,
|
|
},
|
|
"config with an error": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
cnf.Version = "v0"
|
|
return cnf
|
|
}(),
|
|
wantOutput: true,
|
|
wantErr: true,
|
|
},
|
|
"config without provider is not ok": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
cnf.Provider = config.ProviderConfig{}
|
|
return cnf
|
|
}(),
|
|
wantErr: true,
|
|
},
|
|
|
|
"config without required provider": {
|
|
cnf: func() *config.Config {
|
|
cnf := config.Default()
|
|
cnf.Provider.Azure = nil
|
|
return cnf
|
|
}(),
|
|
provider: cloudprovider.Azure,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
|
|
out := &bytes.Buffer{}
|
|
|
|
err := validateConfig(out, tc.cnf)
|
|
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
|
|
assert.Equal(tc.wantOutput, out.Len() > 0)
|
|
})
|
|
}
|
|
}
|