mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-09-23 01:35:52 +00:00
2d8fcd9bf4
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>
76 lines
1.5 KiB
Go
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
|
|
}
|