mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-27 20:10:51 -04:00
monorepo
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
This commit is contained in:
commit
2d8fcd9bf4
362 changed files with 50980 additions and 0 deletions
103
internal/config/config_test.go
Normal file
103
internal/config/config_test.go
Normal file
|
@ -0,0 +1,103 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
||||
"github.com/edgelesssys/constellation/cli/file"
|
||||
"github.com/edgelesssys/constellation/cli/gcp/client"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
def := Default()
|
||||
assert.NotNil(def)
|
||||
}
|
||||
|
||||
func TestFromFile(t *testing.T) {
|
||||
someProviderConfig := &ProviderConfig{
|
||||
GCP: &GCPConfig{
|
||||
FirewallInput: &client.FirewallInput{
|
||||
Ingress: cloudtypes.Firewall{
|
||||
{
|
||||
Name: "firstFirewallRule",
|
||||
Description: "firstFirewallRule description",
|
||||
Protocol: "tcp",
|
||||
Port: 4444,
|
||||
},
|
||||
{
|
||||
Name: "secondFirewallRule",
|
||||
Description: "secondFirewallRule description",
|
||||
Protocol: "udp",
|
||||
Port: 5555,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
configName := "config.json"
|
||||
|
||||
testCases := map[string]struct {
|
||||
from *Config
|
||||
configName string
|
||||
wantResultMutator func(c *Config) // mutates the Default() config to the expected result.
|
||||
wantErr bool
|
||||
}{
|
||||
"overwrite fields": {
|
||||
from: &Config{StatePath: proto.String("test")},
|
||||
configName: configName,
|
||||
wantResultMutator: func(c *Config) { c.StatePath = proto.String("test") },
|
||||
},
|
||||
"overwrite slices": {
|
||||
from: &Config{Provider: someProviderConfig},
|
||||
configName: configName,
|
||||
wantResultMutator: func(c *Config) { c.Provider = someProviderConfig },
|
||||
},
|
||||
"default with empty name": {
|
||||
from: &Config{},
|
||||
configName: "",
|
||||
wantResultMutator: func(c *Config) {},
|
||||
},
|
||||
"err with wrong name": {
|
||||
from: &Config{},
|
||||
configName: "wrongName.json",
|
||||
wantResultMutator: func(c *Config) {},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
fileHandler := file.NewHandler(afero.NewMemMapFs())
|
||||
require.NoError(fileHandler.WriteJSON(configName, tc.from, false))
|
||||
|
||||
result, err := FromFile(fileHandler, tc.configName)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
require.NoError(err)
|
||||
wantResult := Default()
|
||||
tc.wantResultMutator(wantResult)
|
||||
assert.EqualValues(wantResult.StatePath, result.StatePath)
|
||||
assert.EqualValues(wantResult.AdminConfPath, result.AdminConfPath)
|
||||
assert.EqualValues(wantResult.MasterSecretPath, result.MasterSecretPath)
|
||||
assert.EqualValues(wantResult.CoordinatorPort, result.CoordinatorPort)
|
||||
assert.EqualValues(wantResult.AutoscalingNodeGroupsMin, result.AutoscalingNodeGroupsMin)
|
||||
assert.EqualValues(wantResult.AutoscalingNodeGroupsMax, result.AutoscalingNodeGroupsMax)
|
||||
require.NotNil(wantResult.Provider)
|
||||
require.NotNil(wantResult.Provider.GCP, result.Provider.GCP)
|
||||
require.NotNil(wantResult.Provider.GCP.FirewallInput, result.Provider.GCP.FirewallInput)
|
||||
assert.Equal(len(wantResult.Provider.GCP.FirewallInput.Ingress), len(result.Provider.GCP.FirewallInput.Ingress))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue