mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-09 13:38:51 -06:00
unit test getFailsafeIdentifier
This commit is contained in:
65
pkg/service/v0/service_test.go
Normal file
65
pkg/service/v0/service_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/owncloud/ocis-pkg/v2/middleware"
|
||||
"github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
ctxWithUUID = context.WithValue(context.Background(), middleware.UUIDKey, "61445573-4dbe-4d56-88dc-88ab47aceba7")
|
||||
ctxWithEmptyUUID = context.WithValue(context.Background(), middleware.UUIDKey, "")
|
||||
emptyCtx = context.Background()
|
||||
|
||||
scenarios = []struct {
|
||||
name string
|
||||
identifier *proto.Identifier
|
||||
ctx context.Context
|
||||
expect *proto.Identifier
|
||||
}{
|
||||
{
|
||||
name: "context with UUID; identifier = 'me'",
|
||||
ctx: ctxWithUUID,
|
||||
identifier: &proto.Identifier{
|
||||
AccountUuid: "me",
|
||||
},
|
||||
expect: &proto.Identifier{
|
||||
AccountUuid: ctxWithUUID.Value(middleware.UUIDKey).(string),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "context without UUID; identifier = 'me'",
|
||||
ctx: ctxWithEmptyUUID,
|
||||
identifier: &proto.Identifier{
|
||||
AccountUuid: "me",
|
||||
},
|
||||
expect: &proto.Identifier{
|
||||
AccountUuid: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "context with UUID; identifier not 'me'",
|
||||
ctx: ctxWithUUID,
|
||||
identifier: &proto.Identifier{},
|
||||
expect: &proto.Identifier{
|
||||
AccountUuid: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func TestGetFailsafeIdentifier(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
scenario := s
|
||||
t.Run(scenario.name, func(t *testing.T) {
|
||||
got := getFailsafeIdentifier(scenario.ctx, scenario.identifier)
|
||||
assert.NotPanics(t, func() {
|
||||
getFailsafeIdentifier(emptyCtx, scenario.identifier)
|
||||
})
|
||||
assert.Equal(t, scenario.expect, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user