mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-23 23:40:44 -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
75
coordinator/cloudprovider/gcp/ccm_test.go
Normal file
75
coordinator/cloudprovider/gcp/ccm_test.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue