• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang test.Assert函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中eos/server/test.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Test_LoginCheckHandler

func Test_LoginCheckHandler(t *testing.T) {
	tmp := &db.Session{UId: bson.ObjectIdHex("52a4ed348350a921bd000001")}
	db.AddTemp("sessions", tmp)
	tmpU := &db.User{Id: tmp.UId, OrgId: bson.ObjectIdHex("52a4ed348350a921bd000002"), Email: "a", Password: "b"}
	db.AddTemp("users", tmpU)

	msg := &Message{
		msg: `{"type":"loginCheck","data":{
            "session_id": "` + tmp.Id.Hex() + `"
        }}`,
		c: &Connection{owner: &User{}},
	}

	err, _ := HandleMsg(msg)

	cmd := GetLastCmd()
	test.Assert(cmd.Data["status"].(string) == "OK", "it recognises the previous session", t)

	db.DelTemps("sessions")
	db.DelTemps("users")

	HandleMsg(msg)

	cmd = GetLastCmd()
	test.Assert(cmd.Data["status"].(string) == "UNAUTHORIZED", "it does not authorise user when there is no previous session", t)

	msg.msg = `{"type":"loginCheck","data":{"session_id": "invalid"}}`
	err, _ = HandleMsg(msg)
	test.Assert(err != nil, "It returns an error if session id is invalid objectid", t)
	msg.msg = `{"type":"loginCheck","data":{"session_id": 5}}`
	err, _ = HandleMsg(msg)
	test.Assert(err != nil, "It returns an error if session id is invalid string", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:33,代码来源:login_check_handler_test.go


示例2: Test_u_GetOrg

//-------------------------------------------------------
// getting the organisation
//-------------------------------------------------------
func Test_u_GetOrg(t *testing.T) {
	org := setupOrg()

	u := &User{OrgId: NO_ORG}
	test.Assert(u.GetOrg() == nil, "it does not return an org if the daemon is not authorised", t)

	u = &User{OrgId: "123"}
	test.Assert(u.GetOrg() == org, "it does return an org if the daemon is authorised", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:12,代码来源:user_test.go


示例3: Test_d_GetOrg

func Test_d_GetOrg(t *testing.T) {
	org := setupOrg()

	d := &Daemon{OrgId: NO_ORG}
	test.Assert(d.GetOrg() == nil, "it does not return an org if the daemon is not authorised", t)

	d = &Daemon{OrgId: "123"}
	test.Assert(d.GetOrg() == org, "it does return an org if the daemon is authorised", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:9,代码来源:daemon_test.go


示例4: Test_NewOrg

//-------------------------------------------------------
// test handling the organisations
//-------------------------------------------------------
func Test_NewOrg(t *testing.T) {
	orgs = make(map[string]*Organisation)

	orgId := "123"
	org := NewOrg(orgId)

	test.Assert(org != nil, "it creates a new organisation", t)
	test.Assert(len(orgs) == 1, "it is stored in the map of orgs", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:12,代码来源:organisation_test.go


示例5: Test_MonitoringHandlerUser

func Test_MonitoringHandlerUser(t *testing.T) {
	// before
	user := &User{OrgId: "Anonymous"}
	daemon := &Daemon{Id: "a", OrgId: "Anonymous"}
	user.Authorise()

	data1 := &db.Data{"", "cpu", 1000, 12.5}
	data2 := &db.Data{"", "cpu", 1500, 14.5}
	data3 := &db.Data{"", "cpu", 1600, 15.5}
	data4 := &db.Data{"", "cpu", 1900, 11.5}
	data5 := &db.Data{"", "ram", 1200, 9000}
	db.AddTemp("monitoring_of_a", data1)
	db.AddTemp("monitoring_of_a", data2)
	db.AddTemp("monitoring_of_a", data3)
	db.AddTemp("monitoring_of_a", data4)
	db.AddTemp("monitoring_of_a", data5)

	// let's try it from the string...
	msg := &Message{
		msg: `
        {
            "type": "monitoring",
            "data": {
                "daemon_id": "a",
                "parameter": "cpu",
                "from": 1100,
                "to": 1600
            }
        }
        `,
		c: &Connection{owner: user},
	}

	// the daemon is not in the org
	err, _ := HandleMsg(msg)

	test.Assert(err != nil, "it doesn't allow to monitor foreign daemons", t)

	// daemon exists in the org
	daemon.Authorise()

	err, _ = HandleMsg(msg)

	cmd := GetLastCmd()

	test.Assert(err == nil, "it does allow to monitor your daemons", t)
	vals := cmd.Data["values"].(map[string]float64)
	test.Assert(len(vals) == 2, "it returns the right number of answers", t)
	test.Assert(vals["1500"] == 14.5, "it has the correct data", t)
	test.Assert(vals["1600"] == 15.5, "it has the correct data", t)

	// cleaning up
	db.C("monitoring_of_a").DropCollection()
	user.Deauthorise()
	daemon.Deauthorise()
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:56,代码来源:monitoring_handler_test.go


示例6: Test_GetOrg

func Test_GetOrg(t *testing.T) {
	orgs = make(map[string]*Organisation)
	orgs["123"] = &Organisation{}

	org, err := GetOrg("123")
	test.Assert(err == nil && org != nil, "it gets an existing organisation", t)

	org, err = GetOrg("nonexistent")
	test.Assert(err != nil && org == nil, "it returns an error if org not found", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:10,代码来源:organisation_test.go


示例7: Test_GetMessage

//-------------------------------------------------------
// test generating the json
//-------------------------------------------------------
func Test_GetMessage(t *testing.T) {
	cmd := &CmdMessage{Type: "test", Data: make(map[string]interface{})}
	cmd.Data["foo"] = "bar"
	cmd.Conn = &Connection{}
	msg, err := GetMessage(cmd)

	test.Assert(err == nil, "successfully stores the correct message", t)
	test.Assert(msg.msg == `{"type":"test","data":{"foo":"bar"}}`, "produces the expected output", t)
	test.Assert(msg.c == cmd.Conn, "preserves the connection", t)
	test.Assert(cmd.Conn != nil, "does not interfere with the structure", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:controller_test.go


示例8: Test_addDaemon

func Test_addDaemon(t *testing.T) {
	org := setupOrg()

	test.Assert(len(org.Daemons) == 0, "there are no daemons initially", t)
	org.addDaemon("test", &Connection{})
	test.Assert(len(org.Daemons) == 1, "it adds a daemon to an organisation", t)

	err := org.addDaemon("test", &Connection{})
	test.Assert(err != nil, "it doesn't add a duplicate daemon", t)

}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:11,代码来源:organisation_test.go


示例9: Test_DaemonsHandler

func Test_DaemonsHandler(t *testing.T) {
	user := &User{
		Id:    "52a4ed348350a921bd000001",
		OrgId: NO_ORG,
	}
	msg := &Message{
		msg: `{"type":"daemons","data":{}}`,
		c:   &Connection{owner: user},
	}

	// user has to be authorised, to get daemons data
	err, _ := HandleMsg(msg)
	test.Assert(err != nil, "user has to be authorised", t)

	// when there are no daemons, it returns an empty list
	user.OrgId = "Anonymous"
	user.Authorise()

	err, _ = HandleMsg(msg)
	test.Assert(err == nil, "it does not throw an error for authorised user", t)

	cmd := GetLastCmd()
	test.Assert(len(cmd.Data["list"].([]map[string]interface{})) == 0, "it does not return inexistent daemons", t)

	// otherwise, it returns a list of daemons
	d1 := &Daemon{Id: "a", OrgId: "Anonymous", Entry: &db.Daemon{}}
	d2 := &Daemon{Id: "b", OrgId: "Anonymous", Entry: &db.Daemon{}}
	d3 := &Daemon{Id: "c", OrgId: "Another_org", Entry: &db.Daemon{}}
	// FIXME: these circular references look bad
	// we should probably refactor them away later on
	d1.c = &Connection{owner: d1}
	d2.c = &Connection{owner: d2}
	d3.c = &Connection{owner: d3}
	d1.Authorise()
	d2.Authorise()
	d3.Authorise()

	err, _ = HandleMsg(msg)

	cmd = GetLastCmd()
	test.Assert(len(cmd.Data["list"].([]map[string]interface{})) == 2, "it returns only daemons, that are in the same org, as user", t)

	// daemons cannot request it
	msg.c = &Connection{owner: &Daemon{}}

	err, _ = HandleMsg(msg)
	test.Assert(err != nil, "daemons are disallowed", t)

	// cleaning up
	user.Deauthorise()
	d1.Deauthorise()
	d2.Deauthorise()
	d3.Deauthorise()
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:54,代码来源:daemons_handler_test.go


示例10: Test_addUser

func Test_addUser(t *testing.T) {
	org := setupOrg()

	test.Assert(len(org.Users) == 0, "there are no users initially", t)
	org.addUser("test", &Connection{})
	test.Assert(len(org.Users) == 1, "it adds a user to an organisation", t)

	err := org.addUser("test", &Connection{})
	test.Assert(err != nil, "it doesn't add a duplicate user", t)

}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:11,代码来源:organisation_test.go


示例11: Test_u_Authorise_exOrg

func Test_u_Authorise_exOrg(t *testing.T) {
	setupOrg()
	org := NewOrg("Anonymous")
	test.Assert(len(org.Users) == 0, "there are no daemons in the org initially", t)

	u := &User{Id: "test", OrgId: "Anonymous"}

	u.Authorise()

	test.Assert(len(org.Users) == 1, "It adds user to organisation", t)
	test.Assert(u.OrgId == "Anonymous", "It stores org ID in user", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:12,代码来源:user_test.go


示例12: Test_d_Authorise_exOrg

func Test_d_Authorise_exOrg(t *testing.T) {
	setupOrg()
	org := NewOrg("Anonymous")
	test.Assert(len(org.Daemons) == 0, "there are no daemons in the org initially", t)

	d := &Daemon{Id: "test", OrgId: "Anonymous"}

	d.Authorise()

	test.Assert(len(org.Daemons) == 1, "It adds daemon to organisation", t)
	test.Assert(d.OrgId == "Anonymous", "It stores org ID in daemon", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:12,代码来源:daemon_test.go


示例13: Test_sendToDaemons

func Test_sendToDaemons(t *testing.T) {
	org := setupOrg()
	c1 := &Connection{send: make(chan string)}
	c2 := &Connection{send: make(chan string)}
	org.Daemons["test1"] = c1
	org.Daemons["test2"] = c2

	msg := "TestMsg"
	go org.sendToDaemons(msg)

	test.Assert(messageSent(msg, c1.send), "it sends the message to the first daemon's channel", t)
	test.Assert(messageSent(msg, c2.send), "it sends the message to the second daemon's channel", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:13,代码来源:organisation_test.go


示例14: Test_d_Authorise_newOrg

func Test_d_Authorise_newOrg(t *testing.T) {
	setupOrg()
	org, err := GetOrg("Anonymous")
	test.Assert(err != nil, "organisation does not exist", t)

	d := &Daemon{Id: "test", OrgId: "Anonymous"}

	d.Authorise()
	org, err = GetOrg("Anonymous")

	test.Assert(org != nil, "It creates a new org", t)
	test.Assert(len(org.Daemons) == 1, "It adds daemon to organisation", t)
	test.Assert(d.OrgId == "Anonymous", "It stores org ID in daemon", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:daemon_test.go


示例15: Test_u_Deauthorise

//-------------------------------------------------------
// remove itself from the organisation
//-------------------------------------------------------
func Test_u_Deauthorise(t *testing.T) {
	org := setupOrg()
	org.Users["test"] = &Connection{}

	u := &User{Id: "test", OrgId: NO_ORG}

	err := u.Deauthorise()
	test.Assert(err != nil, "it does not deauthorise already deauthorised user", t)

	u.OrgId = "123"
	err = u.Deauthorise()
	test.Assert(err == nil && len(org.Users) == 0, "it removes a user from organisation", t)
	test.Assert(u.OrgId == NO_ORG, "it sets the user organisation to none", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:17,代码来源:user_test.go


示例16: Test_u_Authorise_newOrg

//-------------------------------------------------------
// add yourself to a organisation
//-------------------------------------------------------
func Test_u_Authorise_newOrg(t *testing.T) {
	setupOrg()
	org, err := GetOrg("Anonymous")
	test.Assert(err != nil, "organisation does not exist", t)

	u := &User{Id: "test", OrgId: "Anonymous"}

	u.Authorise()
	org, err = GetOrg("Anonymous")

	test.Assert(org != nil, "It creates a new org", t)
	test.Assert(len(org.Users) == 1, "It adds user to organisation", t)
	test.Assert(u.OrgId == "Anonymous", "It stores org ID in user", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:17,代码来源:user_test.go


示例17: Test_RegisterHandler

func Test_RegisterHandler(t *testing.T) {
	spy, called := getHandlerSpy()

	oldLen := len(handlers)
	RegisterHandler("_test", spy)

	test.Assert(len(handlers)-oldLen == 1, "created a new handler", t)
	test.Assert(*called == false, "our spy works", t)
	handlers["_test"](&CmdMessage{})
	test.Assert(*called == true, "associated with specified function", t)

	// cleaning up
	delete(handlers, "_test")
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:controller_test.go


示例18: Test_DeregisterHandler

func Test_DeregisterHandler(t *testing.T) {
	spy, _ := getHandlerSpy()

	handlers["_test"] = spy

	oldLen := len(handlers)
	DeregisterHandler("_test")
	test.Assert(oldLen-len(handlers) == 1, "deletes the handler", t)
	err := DeregisterHandler("_again")
	test.Assert(err != nil, "fails when no such handler exists", t)

	// cleaning up
	delete(handlers, "_test")
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:controller_test.go


示例19: Test_d_Deauthorise

func Test_d_Deauthorise(t *testing.T) {
	org := setupOrg()
	org.Daemons["test"] = &Connection{}

	d := &Daemon{Id: "test", OrgId: NO_ORG}

	err := d.Deauthorise()
	test.Assert(err != nil, "it does not deauthorise already deauthorised daemon", t)

	d.OrgId = "123"
	err = d.Deauthorise()
	test.Assert(err == nil && len(org.Daemons) == 0, "it removes a user from organisation", t)
	test.Assert(d.OrgId == NO_ORG, "it sets the user organisation to none", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:daemon_test.go


示例20: Test_u_AuthFromSession

//-------------------------------------------------------
// get the id from the session
//-------------------------------------------------------
func Test_u_AuthFromSession(t *testing.T) {
	tmp := &db.Session{UId: bson.ObjectIdHex("52a4ed348350a921bd000002")}
	db.AddTemp("sessions", tmp)

	uid, err := AuthFromSession(tmp.Id.Hex())

	test.Assert(uid.Hex() == "52a4ed348350a921bd000002", "It finds the user when he is in the session", t)
	test.Assert(err == nil, "It does not throw an error then", t)

	db.DelTemps("sessions")
	uid, err = AuthFromSession(tmp.Id.Hex())

	test.Assert(uid.Hex() != "52a4ed348350a921bd000002", "It does not find the user that is not in the session", t)
	test.Assert(err != nil, "It does throw an error then", t)
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:18,代码来源:user_test.go



注:本文中的eos/server/test.Assert函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.New函数代码示例发布时间:2022-05-24
下一篇:
Golang transport.TcpMessage类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap