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