本文整理汇总了Golang中lib/wcg/gae/gaetest.FixtureFromMap函数的典型用法代码示例。如果您正苦于以下问题:Golang FixtureFromMap函数的具体用法?Golang FixtureFromMap怎么用?Golang FixtureFromMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FixtureFromMap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_EntityQuery
func Test_EntityQuery(t *testing.T) {
assert := gaetest.NewAssert(t)
router := wcg.NewRouter()
router.GET("/api/",
EntityQuery(testEntity.Query().Limit(2)),
)
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"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "8", "ID": "8"},
map[string]interface{}{"_kind": testEntity.String(), "_key": "9", "ID": "9"},
})
var got entities.Pagination
req := ts.GET("/api/")
res := req.RouteTo(router)
assert.HTTPStatus(200, res)
assert.JSONResponse(&got, res)
assert.EqInt(2, got.Length())
assert.EqInt(2, got.Next.N)
assert.EqInt(1, got.Next.P)
assert.Nil(got.Previous)
// TODO: got does not has []TEntity, but has []map[string]interface{}.
// Need to provide a way to make got have []TEntity or []*TEntity
}
示例2: 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")
}
示例3: 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")
}
示例4: 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])
}
示例5: Test_EntityStreaming
func Test_EntityStreaming(t *testing.T) {
assert := gaetest.NewAssert(t)
router := wcg.NewRouter()
router.GET("/api/",
EntityStreaming(testEntity.Query(), false),
)
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"},
})
req := ts.GET("/api/")
res := req.RouteTo(router)
assert.HTTPStatus(200, res)
assert.HTTPBodyString(
`{"id":"1","value":0,"updated_at":"0001-01-01T00:00:00Z"}
{"id":"2","value":0,"updated_at":"0001-01-01T00:00:00Z"}
{"id":"3","value":0,"updated_at":"0001-01-01T00:00:00Z"}
{"id":"4","value":0,"updated_at":"0001-01-01T00:00:00Z"}
`,
res,
)
}
示例6: 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")
}
示例7: Test_EntityPut
func Test_EntityPut(t *testing.T) {
assert := gaetest.NewAssert(t)
router := wcg.NewRouter()
router.PUT("/api/:key.json",
ParseForm(nil),
EntityPut(testEntity.Put(), "key"),
)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
})
var got TEntity
req := ts.PUTForm("/api/1.json", url.Values{
"value": []string{"1"},
})
res := req.RouteTo(router)
assert.HTTPStatus(200, res)
assert.JSONResponse(&got, res)
assert.EqStr("1", got.ID)
assert.EqInt(1, got.Value)
_, one := testEntity.Get().Key(got.ID).MustOne(ts.GET("/").Request)
assert.EqStr(got.ID, one.(*TEntity).ID)
assert.EqInt(1, one.(*TEntity).Value)
}
示例8: 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)
}
示例9: Test_Delete
func Test_Delete(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"},
})
key := testEntity.Delete().Key("1").MustCommit(ts.DELETE("/").Request)
assert.EqStr("1", key.StringID())
}
示例10: Test_DeleteMulti
func Test_DeleteMulti(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"},
})
keys, err := testEntity.DeleteMulti().Keys("1", "2").Commit(ts.GET("/").Request)
assert.Nil(err)
assert.EqInt(2, len(keys), "2 keys should be deleted")
}
示例11: Test_Query_WithPagination
func Test_Query_WithPagination(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"},
})
// pagination with n = 3
page := testEntity.Query().MustExecute(ts.GET("/?p=0&n=3").Request)
got := page.Data.([]TEntity)
assert.EqInt(3, len(got), "len(Pagination.Data)")
assert.Nil(page.Previous, "Pagination.Previous")
assert.NotNil(page.Next, "Pagination.Next")
assert.EqInt(1, page.Next.P, "Pagination.Next.P")
assert.EqInt(3, page.Next.N, "Pagination.Next.N")
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")
page = testEntity.Query().MustExecute(ts.GET("/?p=1&n=3").Request)
got = page.Data.([]TEntity)
assert.EqInt(3, len(got), "len(Pagination.Data)")
assert.NotNil(page.Previous, "Pagination.Previous")
assert.EqInt(0, page.Previous.P, "Pagination.Next.P")
assert.EqInt(3, page.Previous.N, "Pagination.Next.N")
assert.NotNil(page.Next, "Pagination.Next")
assert.EqInt(2, page.Next.P, "Pagination.Next.P")
assert.EqInt(3, page.Next.N, "Pagination.Next.N")
assert.EqStr("4", got[0].ID, "Pagination.Data[0].ID (got = 1)")
assert.EqStr("5", got[1].ID, "Pagination.Data[1].ID (got = 1)")
assert.EqStr("6", got[2].ID, "Pagination.Data[2].ID (got = 1)")
page = testEntity.Query().MustExecute(ts.GET("/?p=2&n=3").Request)
got = page.Data.([]TEntity)
assert.EqInt(1, len(got), "len(Pagination.Data)")
assert.NotNil(page.Previous, "Pagination.Previous")
assert.EqInt(1, page.Previous.P, "Pagination.Next.P")
assert.EqInt(3, page.Previous.N, "Pagination.Next.N")
assert.Nil(page.Next, "Pagination.Next")
assert.EqStr("7", got[0].ID, "Pagination.Data[0].ID (got = 2)")
}
示例12: Test_DeleteMulti_NonExistingKey
func Test_DeleteMulti_NonExistingKey(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"},
})
keys, err := testEntity.DeleteMulti().Keys("not-exist").Commit(ts.GET("/").Request)
assert.Nil(err)
assert.EqInt(1, len(keys), "Should return num keys even if they do not exist")
assert.EqStr("not-exist", keys[0].StringID())
}
示例13: Test_DeleteQuery
func Test_DeleteQuery(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"},
})
deleted := testEntity.DeleteQuery().Filter("ID =", "3").MustCommit(ts.GET("/").Request)
assert.EqInt(1, deleted)
exists := testEntity.Query().MustCount(ts.GET("/").Request)
assert.EqInt(5, exists)
}
示例14: Test_Query_WithProject
func Test_Query_WithProject(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", "Digit": 11},
map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2", "Digit": 12},
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 := testEntity.Query().Project("Digit").MustExecute(ts.GET("/").Request)
got := page.Data.([]TEntity)
assert.EqInt(2, len(got), "len(Pagination.Data)")
assert.EqStr("", got[0].ID)
assert.EqInt(11, got[0].Digit)
}
示例15: Test_EntityDelete
func Test_EntityDelete(t *testing.T) {
assert := gaetest.NewAssert(t)
router := wcg.NewRouter()
router.GET("/api/:key.json",
EntityDelete(testEntity.Delete(), "key"),
)
gaetest.CleanupDatastore(ts.Context)
gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{
map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"},
})
req := ts.GET("/api/1.json")
res := req.RouteTo(router)
assert.HTTPStatus(200, res)
_, obj := testEntity.Get().Key("1").MustOne(ts.GET("/").Request)
assert.Nil(obj)
}