constellation/coordinator/cloudprovider/gcp/ccm_test.go
Leonard Cohnen 2d8fcd9bf4 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>
2022-03-22 16:09:39 +01:00

76 lines
1.5 KiB
Go

package gcp
import (
"errors"
"testing"
"github.com/edgelesssys/constellation/coordinator/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrepareInstance(t *testing.T) {
err := errors.New("some err")
vpnIP := "192.0.2.0"
instance := core.Instance{
Name: "someInstance",
ProviderID: "gce://someProjectID/someZone/someInstance",
IPs: []string{"192.0.2.0"},
}
testCases := map[string]struct {
writer stubWriter
expectErr bool
expectedConfig string
}{
"prepare works": {
expectedConfig: `[global]
project-id = someProjectID
use-metadata-server = false
`,
},
"GCE conf write error is detected": {
writer: stubWriter{writeErr: err},
expectErr: true,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ccm := CloudControllerManager{writer: &tc.writer}
err := ccm.PrepareInstance(instance, vpnIP)
if tc.expectErr {
assert.Error(err)
return
}
require.NoError(err)
assert.ElementsMatch([]string{tc.expectedConfig}, tc.writer.configs)
})
}
}
func TestTrivialCCMFunctions(t *testing.T) {
assert := assert.New(t)
cloud := CloudControllerManager{}
assert.NotEmpty(cloud.Image())
assert.NotEmpty(cloud.Path())
assert.NotEmpty(cloud.Name())
assert.True(cloud.Supported())
}
type stubWriter struct {
writeErr error
configs []string
}
func (s *stubWriter) WriteGCEConf(config string) error {
s.configs = append(s.configs, config)
return s.writeErr
}