Skip to content

Commit

Permalink
fix tests for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Sep 3, 2024
1 parent 2ff784e commit c1b74d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions pkg/user/manager/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/pkg/user/manager/registry"
"google.golang.org/protobuf/proto"
)

func init() {
Expand Down Expand Up @@ -57,11 +58,11 @@ func (m *manager) Configure(ml map[string]interface{}) error {
func (m *manager) GetUser(ctx context.Context, uid *userpb.UserId, skipFetchingGroups bool) (*userpb.User, error) {
if user, ok := m.catalog[uid.OpaqueId]; ok {
if uid.Idp == "" || user.Id.Idp == uid.Idp {
u := *user
u := proto.Clone(user).(*userpb.User)
if skipFetchingGroups {
u.Groups = nil
}
return &u, nil
return u, nil
}
}
return nil, errtypes.NotFound(uid.OpaqueId)
Expand All @@ -70,11 +71,11 @@ func (m *manager) GetUser(ctx context.Context, uid *userpb.UserId, skipFetchingG
func (m *manager) GetUserByClaim(ctx context.Context, claim, value string, skipFetchingGroups bool) (*userpb.User, error) {
for _, u := range m.catalog {
if userClaim, err := extractClaim(u, claim); err == nil && value == userClaim {
user := *u
u2 := proto.Clone(u).(*userpb.User)
if skipFetchingGroups {
user.Groups = nil
u2.Groups = nil
}
return &user, nil
return u2, nil
}
}
return nil, errtypes.NotFound(value)
Expand Down Expand Up @@ -103,11 +104,11 @@ func (m *manager) FindUsers(ctx context.Context, query string, skipFetchingGroup
users := []*userpb.User{}
for _, u := range m.catalog {
if userContains(u, query) {
user := *u
user := proto.Clone(u).(*userpb.User)
if skipFetchingGroups {
user.Groups = nil
}
users = append(users, &user)
users = append(users, user)
}
}
return users, nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/user/manager/demo/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
"google.golang.org/protobuf/proto"
)

var ctx = context.Background()
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestUserManager(t *testing.T) {

// positive test GetUserByClaim by uid
resUserByUID, _ := manager.GetUserByClaim(ctx, "uid", "123", false)
if !reflect.DeepEqual(resUserByUID, userEinstein) {
if !proto.Equal(resUserByUID, userEinstein) {
t.Fatalf("user differs: expected=%v got=%v", userEinstein, resUserByUID)
}

Expand All @@ -71,13 +72,13 @@ func TestUserManager(t *testing.T) {

// positive test GetUserByClaim by mail
resUserByEmail, _ := manager.GetUserByClaim(ctx, "mail", "einstein@example.org", false)
if !reflect.DeepEqual(resUserByEmail, userEinstein) {
if !proto.Equal(resUserByEmail, userEinstein) {
t.Fatalf("user differs: expected=%v got=%v", userEinstein, resUserByEmail)
}

// positive test GetUserByClaim by uid without groups
resUserByUIDWithoutGroups, _ := manager.GetUserByClaim(ctx, "uid", "123", true)
if !reflect.DeepEqual(resUserByUIDWithoutGroups, userEinsteinWithoutGroups) {
if !proto.Equal(resUserByUIDWithoutGroups, userEinsteinWithoutGroups) {
t.Fatalf("user differs: expected=%v got=%v", userEinsteinWithoutGroups, resUserByUIDWithoutGroups)
}

Expand All @@ -96,7 +97,7 @@ func TestUserManager(t *testing.T) {

// test FindUsers
resUser, _ := manager.FindUsers(ctx, "einstein", false)
if !reflect.DeepEqual(resUser, []*userpb.User{userEinstein}) {
if !proto.Equal(resUser[0], userEinstein) {
t.Fatalf("user differs: expected=%v got=%v", []*userpb.User{userEinstein}, resUser)
}

Expand Down

0 comments on commit c1b74d1

Please sign in to comment.