当前位置: 首页>>代码示例>>Golang>>正文


Golang Manager.FindAllUser方法代码示例

本文整理汇总了Golang中github.com/kidstuff/auth/authmodel.Manager.FindAllUser方法的典型用法代码示例。如果您正苦于以下问题:Golang Manager.FindAllUser方法的具体用法?Golang Manager.FindAllUser怎么用?Golang Manager.FindAllUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/kidstuff/auth/authmodel.Manager的用法示例。


在下文中一共展示了Manager.FindAllUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testManagerFindAllUser

// testManagerFindAllUser add 10 users the do test about partial and projection select
func testManagerFindAllUser(t *testing.T, mngr authmodel.Manager, gid string) {
	users := make([]*authmodel.User, 10)
	var err error
	users[0], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[1], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[2], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[3], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[4], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[5], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[6], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[7], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[8], err = mngr.AddUserDetail("[email protected]", "testing123edc", true, nil, nil, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[9], err = mngr.AddUserDetail("[email protected]", "testing123edc", true, nil, nil, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	// get all user at the same time
	// should return the full list of 10 users
	userList, err := mngr.FindAllUser(-1, "", nil, nil)
	if n := len(userList); n != 10 {
		t.Fatal("get all user failed, expect 10 users, found", n)
	}

	// get all user belong to gid
	userList, err = mngr.FindAllUser(-1, "", nil, []string{gid})
	if n := len(userList); n != 2 {
		t.Fatal("get all user with groups id failed, expect 2 users, found", n)
	}

	// get a single user with specific feilds.
	userList, err = mngr.FindAllUser(1, "", []string{"Id", "Approved"}, nil)
	if n := len(userList); n != 1 {
		t.Fatal("get all user failed, expect 1 users, found", n)
	}

	if userList[0].Id == nil || userList[0].Approved == nil {
		t.Fatal("get all user failed retrieve specifiec fields")
	}

	if u := userList[0]; u.Email != nil || u.Pwd != nil || u.LastActivity != nil {
		t.Fatal("get all user failed not retrieved unspecific fields")
	}

	// get a part of user list
	userList1, err := mngr.FindAllUser(5, "", nil, nil)
	if n := len(userList1); n != 5 {
		t.Fatal("get all user failed, expect 5 but got", n)
	}

	// get the other part
	userList2, err := mngr.FindAllUser(5, *userList1[4].Id, nil, nil)
	if n := len(userList2); n != 5 {
		t.Fatal("get all user with offset id failed, expect 5 but got", n)
	}

	// and check if they are "paging" right
	for _, u1 := range userList1 {
		for _, u2 := range userList2 {
			if *u1.Id == *u2.Id {
				t.Fatal("get all user failed with limit and offset")
			}
		}
//.........这里部分代码省略.........
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:101,代码来源:mngr_test.go


注:本文中的github.com/kidstuff/auth/authmodel.Manager.FindAllUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。