2022-06-28 10:08:05 -04:00
|
|
|
package gcp
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/coordinator/role"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m,
|
|
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
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
|
|
|
}{
|
|
|
|
"coordinator role": {
|
|
|
|
metadata: map[string]string{
|
2022-06-28 10:08:05 -04:00
|
|
|
roleMetadataKey: role.Coordinator.String(),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantRole: role.Coordinator,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"node role": {
|
|
|
|
metadata: map[string]string{
|
2022-06-28 10:08:05 -04:00
|
|
|
roleMetadataKey: role.Node.String(),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantRole: role.Node,
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|