2022-09-05 09:06:08 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-28 16:08:05 +02:00
|
|
|
package gcp
|
2022-03-22 16:03:15 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-26 09:42:40 +00:00
|
|
|
"github.com/edgelesssys/constellation/internal/role"
|
2022-03-22 16:03:15 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExtractRole(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 16:54:05 +02:00
|
|
|
metadata map[string]string
|
|
|
|
wantRole role.Role
|
2022-03-22 16:03:15 +01:00
|
|
|
}{
|
2022-06-29 15:26:29 +02:00
|
|
|
"bootstrapper role": {
|
2022-03-22 16:03:15 +01:00
|
|
|
metadata: map[string]string{
|
2022-06-29 15:26:29 +02:00
|
|
|
roleMetadataKey: role.ControlPlane.String(),
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
2022-06-29 15:26:29 +02:00
|
|
|
wantRole: role.ControlPlane,
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
|
|
|
"node role": {
|
|
|
|
metadata: map[string]string{
|
2022-06-29 15:26:29 +02:00
|
|
|
roleMetadataKey: role.Worker.String(),
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
2022-06-29 15:26:29 +02:00
|
|
|
wantRole: role.Worker,
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
|
|
|
"unknown role": {
|
|
|
|
metadata: map[string]string{
|
2022-06-28 16:08:05 +02:00
|
|
|
roleMetadataKey: "some-unknown-role",
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
2022-04-26 16:54:05 +02:00
|
|
|
wantRole: role.Unknown,
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
|
|
|
"no role": {
|
2022-04-26 16:54:05 +02:00
|
|
|
wantRole: role.Unknown,
|
2022-03-22 16:03:15 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2022-06-28 16:08:05 +02:00
|
|
|
role := extractRole(tc.metadata)
|
2022-03-22 16:03:15 +01:00
|
|
|
|
2022-04-26 16:54:05 +02:00
|
|
|
assert.Equal(tc.wantRole, role)
|
2022-03-22 16:03:15 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|