本文整理汇总了Golang中lib/wcg/gae/gaetest.NewAssert函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAssert函数的具体用法?Golang NewAssert怎么用?Golang NewAssert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAssert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_GetMulti_Cache
func Test_GetMulti_Cache(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
})
driver := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
_, list, err := testEntity.GetMulti().Keys("1", "3").Cache(true).List(ts.GET("/").Request)
got := list.([]*TEntity)
assert.Nil(err)
assert.EqInt(2, len(got))
assert.EqStr("1", got[0].ID)
assert.Nil(got[1])
assert.OK(driver.Exists("ent.TestEntity.1"))
assert.OK(driver.Exists("ent.TestEntity.3"))
var t1, t3 TEntity
driver.Get("ent.TestEntity.1", &t1)
driver.Get("ent.TestEntity.3", &t3)
assert.EqStr("1", t1.ID)
assert.EqStr("", t3.ID)
got = make([]*TEntity, 2)
driver.GetMulti([]string{"ent.TestEntity.1", "ent.TestEntity.3"}, got)
assert.EqStr("1", got[0].ID)
assert.Nil(got[1])
}
示例2: Test_Put_Update
func Test_Put_Update(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "3", "ID": "3"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "4", "ID": "4"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "5", "ID": "5"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "6", "ID": "6"},
})
var ent, err = testEntity.CreateEntityFromForm(url.Values{
"desc": []string{"hogehoge"},
"digit": []string{"2"},
"content_bytes": []string{"abcdef"},
})
_, _ent, err := testEntity.Put().Key("1").Update(ts.PUTForm("/1", nil).Request, ent)
got := _ent.(*TEntity)
assert.Nil(err)
assert.EqStr("1", got.ID)
assert.EqInt(2, got.Digit)
assert.EqStr("hogehoge", got.Desc)
assert.EqStr("abcdef", string(got.ContentBytes))
assert.OK(got.BeforeSaveProcessed, "BeforeSave triggerd")
assert.OK(got.AfterSaveProcessed, "AfterSave triggerd")
}
示例3: Test_API_SystemStats_Query
func Test_API_SystemStats_Query(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_SystemStats_Query.json", nil, "intern.home"), "fixture")
app := NewApp()
req := ts.GET("/api/intern/home/stats/servers/dummy/system/")
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got []home.SystemStats
assert.JSONResponse(&got, res)
assert.EqInt(0, len(got), string(res.Body))
req = ts.GET("/api/intern/home/stats/servers/dummy/system/?until=2014-12-01T11:00:00Z")
res = req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
assert.JSONResponse(&got, res)
assert.EqInt(2, len(got), string(res.Body))
tempnow, _ := wcg.ParseDateTime("2014-12-01T11:00:00Z")
lib.TemporarySetNow(tempnow, func() {
req := ts.GET("/api/intern/home/stats/servers/dummy/system/")
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got []home.SystemStats
assert.JSONResponse(&got, res)
assert.EqInt(2, len(got), string(res.Body))
})
}
示例4: Test_API_Tasks_Crawlers_Ameblo_EntryLists
func Test_API_Tasks_Crawlers_Ameblo_EntryLists(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Tasks_Crawlers_Ameblo_EntryLists.json", nil, "hplink"), "fixture")
httptest.StartMockServer(func(mock *httptest.MockServer) {
mock.Routes().GET("/morningmusume-9ki/entrylist.html", middleware.ServeFile("./fixtures/mocks/ameblo.jp//morningmusume-9ki/entrylist.html"))
crawler.MockExternalResource(map[string]string{
"http://ameblo.jp/morningmusume-9ki/entrylist.html": fmt.Sprintf("%s//morningmusume-9ki/entrylist.html", mock.BaseURL()),
}, func() {
runner := testhelper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnMonitor(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.OnTrigger(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.Run("/api/hplink/tasks/crawlers/ameblo/entrylists/", url.Values{})
p := entities.AmebloPost.Query().Order("-PostAt").MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(20, len(postList))
assert.EqStr("ノーメイク☆譜久村聖", postList[0].Title)
assert.EqStr("", postList[0].Theme)
assert.EqStr("morningmusume.mizuki_fukumura", postList[0].MemberKey)
assert.EqStr("http://ameblo.jp/morningmusume-9ki/", postList[0].SettingsURL)
p = entities.CrawlerSettings.Query().Filter("URL=", "http://ameblo.jp/morningmusume-9ki/").MustExecute(ts.GET("/").Request)
assert.EqInt(1, p.Length())
settings := p.Head().(*hplink.CrawlerSettings)
assert.EqInt(int(hplink.CrawlerStatusSuccess), int(settings.Status))
})
})
}
示例5: Test_Kind_CreateEntityFromJSON
func Test_Kind_CreateEntityFromJSON(t *testing.T) {
assert := gaetest.NewAssert(t)
jsonString := `{
"digit": 34225940,
"desc": "foo",
"slice_type": ["1", "2", "3"],
"slice_float_type": [1.1, 2.5, 3.4],
"bool_type": true,
"float_type": 1.4,
"id": "1"
}`
ent, _ := testEntity.CreateEntityFromJSON([]byte(jsonString))
got := ent.(*TEntity)
assert.EqInt(34225940, got.Digit)
assert.EqStr("foo", got.Desc)
assert.EqStr("1", got.SliceType[0])
assert.EqStr("2", got.SliceType[1])
assert.EqStr("3", got.SliceType[2])
assert.EqFloat64(1.1, got.SliceFloatType[0])
assert.EqFloat64(2.5, got.SliceFloatType[1])
assert.EqFloat64(3.4, got.SliceFloatType[2])
assert.OK(got.BoolType)
assert.EqFloat64(1.4, got.FloatType)
assert.EqStr("", got.ID, "id field should not be parsed")
}
示例6: Test_APITokenOnly
func Test_APITokenOnly(t *testing.T) {
assert := gaetest.NewAssert(t)
router := wcg.NewRouter()
router.GET("/",
APITokenOnly(),
wcg.AnonymousHandler(func(res *wcg.Response, req *wcg.Request) {
res.WriteString("OK")
}),
)
req := ts.GET("/")
res := req.RouteTo(router)
assert.HTTPStatus(401, res)
req = ts.GET("/")
req.Request.User = &request.APITokenUser{
&models.APIToken{
Token: "testuser",
Description: "test api token user",
CreatedAt: time.Now(),
AlertOn: time.Duration(0),
LastAccess: time.Now(),
},
}
res = req.RouteTo(router)
assert.HTTPStatus(200, res)
}
示例7: Test_Query_WithCache
func Test_Query_WithCache(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "3", "ID": "3"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "4", "ID": "4"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "5", "ID": "5"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "6", "ID": "6"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "7", "ID": "7"},
})
page, err := testEntity.Query().Cache("123").Execute(ts.GET("/").Request)
got := page.Data.([]TEntity)
assert.Nil(err)
assert.EqInt(7, len(got), "len(Pagination.Data)")
driver := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
assert.OK(driver.Exists("query.TestEntity.123"))
// cache still exists even after removing data.
gaetest.CleanupDatastore(ts.Context)
page, err = testEntity.Query().Cache("123").Execute(ts.GET("/").Request)
got = page.Data.([]TEntity)
assert.Nil(err)
assert.EqInt(7, len(got))
assert.EqStr("1", got[0].ID)
}
示例8: Test_API_POST_Me_Gates
func Test_API_POST_Me_Gates(t *testing.T) {
assert := gaetest.NewAssert(t)
app := NewApp()
req := ts.POSTForm("/api/users/me/gates/", url.Values{
"keys": []string{"foo"},
})
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got map[string]bool
assert.JSONResponse(&got, res)
assert.EqInt(1, len(got))
assert.Not(got["foo"])
req = ts.POSTForm("/api/users/me/gates/", url.Values{
"keys": []string{"foo"},
})
testhelper.TemporaryAllow(req, "foo", func() {
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got map[string]bool
assert.JSONResponse(&got, res)
assert.EqInt(1, len(got))
assert.OK(got["foo"])
})
}
示例9: Test_Query
func Test_Query(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "3", "ID": "3"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "4", "ID": "4"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "5", "ID": "5"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "6", "ID": "6"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "7", "ID": "7"},
})
// no pagination parameter specified -> returns all entities
page := testEntity.Query().MustExecute(ts.GET("/").Request)
got := page.Data.([]TEntity)
assert.EqInt(7, len(got), "len(Pagination.Data)")
assert.Nil(page.Next, "Pagination.Next")
assert.Nil(page.Previous, "Pagination.Previous")
assert.EqStr("1", got[0].ID, "Pagination.Data[0].ID")
assert.EqStr("2", got[1].ID, "Pagination.Data[1].ID")
assert.EqStr("3", got[2].ID, "Pagination.Data[2].ID")
assert.EqStr("4", got[3].ID, "Pagination.Data[3].ID")
assert.EqStr("5", got[4].ID, "Pagination.Data[4].ID")
assert.EqStr("6", got[5].ID, "Pagination.Data[5].ID")
assert.EqStr("7", got[6].ID, "Pagination.Data[6].ID")
}
示例10: Test_Query_NoData
func Test_Query_NoData(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context)
page := testEntity.Query().MustExecute(ts.GET("/").Request)
got := page.Data.([]TEntity)
assert.EqInt(0, len(got))
}
示例11: Test_API_CronStatsCleanup
func Test_API_CronStatsCleanup(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_SystemStats_Query.json", nil, "intern.home"), "fixture")
sk, _ := Server.Get().Key("dummy").MustOne(ts.GET("/").Request)
c := SystemStats.Query().Ancestor(sk).MustCount(ts.GET("/").Request)
assert.EqInt(2, c)
tempnow, _ := wcg.ParseDateTime("2014-12-01T11:00:00Z")
lib.TemporarySetNow(tempnow, func() {
app := NewApp()
req := ts.GET("/cron/intern/home/stats/cleanup/")
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
// confirm nothing deleted
c = SystemStats.Query().Ancestor(sk).MustCount(ts.GET("/").Request)
assert.EqInt(2, c)
})
app := NewApp()
req := ts.GET("/cron/intern/home/stats/cleanup/")
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
// everything deleted since it's old
c = SystemStats.Query().Ancestor(sk).MustCount(ts.GET("/").Request)
assert.EqInt(0, c)
}
示例12: Test_Session
func Test_Session(t *testing.T) {
assert := gaetest.NewAssert(t)
handler := wcg.AnonymousHandler(func(res *wcg.Response, req *wcg.Request) {
if req.Session == nil {
res.WriteString("No Session")
} else {
res.WriteString("Has Session")
}
})
router := wcg.NewRouter()
Use(router, func() {
router.GET("/api/foo", handler)
router.GET("/static/foo", handler)
router.GET("/cron/foo", handler)
})
req := ts.GET("/api/foo")
assert.EqStr("Has Session", string(req.RouteTo(router).Body), "Has Session")
req = ts.GET("/api/foo")
req.AddHeader(request.APITokenHeader, "FOO")
assert.EqStr("No Session", string(req.RouteTo(router).Body), "No Session")
req = ts.GET("/api/foo")
req.AddHeader(request.TaskQueueHeader, "true")
assert.EqStr("No Session", string(req.RouteTo(router).Body), "No Session")
req = ts.GET("/static/foo")
assert.EqStr("No Session", string(req.RouteTo(router).Body), "No Session")
req = ts.GET("/cron/foo")
req.AddHeader(request.CronHeader, "true")
assert.EqStr("No Session", string(req.RouteTo(router).Body), "No Session")
}
示例13: Test_Delete_CacheInvalidation
func Test_Delete_CacheInvalidation(t *testing.T) {
assert := gaetest.NewAssert(t)
driver := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "3", "ID": "3"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "4", "ID": "4"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "5", "ID": "5"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "6", "ID": "6"},
})
// create caches
testEntity.Query().Cache("123").MustExecute(ts.GET("/").Request)
testEntity.Get().Key("1").Cache(true).MustOne(ts.GET("/").Request)
assert.OK(driver.Exists("ent.TestEntity.1"), "An entyty cache should exist")
assert.OK(driver.Exists("query.TestEntity.123"), "A query cache should exist")
testEntity.Delete().Key("1").Cache("123").MustCommit(ts.GET("/").Request)
assert.Not(driver.Exists("ent.TestEntity.1"), "Entity cache should be invalidated")
assert.Not(driver.Exists("query.TestEntity.123"), "Query cache should be invalidated")
}
示例14: Test_API_Tasks_Crawlers_Ameblo_Posts
func Test_API_Tasks_Crawlers_Ameblo_Posts(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Tasks_Crawlers_Ameblo_Posts.json", nil, "hplink"), "fixture")
p := entities.AmebloPost.Query().MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(1, len(postList))
httptest.StartMockServer(func(mock *httptest.MockServer) {
mock.Routes().GET("/morningmusume-9ki/post.html", middleware.ServeFile("./fixtures/mocks/ameblo.jp//morningmusume-9ki/post.html"))
crawler.MockExternalResource(map[string]string{
"http://ameblo.jp/morningmusume-9ki/entry-12201946654.html": fmt.Sprintf("%s//morningmusume-9ki/post.html", mock.BaseURL()),
}, func() {
runner := testhelper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnMonitor(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.OnTrigger(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.Run("/api/hplink/tasks/crawlers/ameblo/posts/", url.Values{})
p := entities.AmebloPost.Query().MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(1, len(postList))
assert.EqStr("ノーメイク☆譜久村聖", postList[0].Title)
assert.EqStr("譜久村聖", postList[0].Theme)
assert.EqStr("morningmusume.mizuki_fukumura", postList[0].MemberKey)
// It also creates a URL cache
assert.EqInt(1, entities.URLCache.Query().MustCount(ts.GET("/").Request))
})
})
}
示例15: Test_Kind_CreateEntitiesFromJSON
func Test_Kind_CreateEntitiesFromJSON(t *testing.T) {
assert := gaetest.NewAssert(t)
jsonString := `[
{"digit": 34225940},
{"desc": "foo"},
{"slice_type": ["1", "2", "3"]},
{"slice_float_type": [1.1, 2.5, 3.4]},
{"bool_type": true},
{"float_type": 1.4},
{"id": "1"}
]`
ent, err := testEntity.CreateEntitiesFromJSON(bytes.NewBuffer([]byte(jsonString)))
assert.Nil(err)
got := ent.([]*TEntity)
assert.EqInt(7, len(got))
assert.EqInt(34225940, got[0].Digit)
assert.EqStr("foo", got[1].Desc)
assert.EqInt(3, len(got[2].SliceType))
assert.EqStr("1", got[2].SliceType[0])
assert.EqStr("2", got[2].SliceType[1])
assert.EqStr("3", got[2].SliceType[2])
assert.EqFloat64(1.1, got[3].SliceFloatType[0])
assert.EqFloat64(2.5, got[3].SliceFloatType[1])
assert.EqFloat64(3.4, got[3].SliceFloatType[2])
assert.OK(got[4].BoolType)
assert.EqFloat64(1.4, got[5].FloatType)
assert.EqStr("", got[6].ID, "id field should not be parsed")
}