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


Golang gaetest.CleanupDatastore函数代码示例

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


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

示例1: 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)
}
开发者ID:speedland,项目名称:service,代码行数:28,代码来源:query_test.go

示例2: Test_Query_NoData_WithCache

func Test_Query_NoData_WithCache(t *testing.T) {
	assert := gaetest.NewAssert(t)
	gaetest.CleanupDatastore(ts.Context)
	page := testEntity.Query().Cache("nodata").MustExecute(ts.GET("/").Request)
	gaetest.CleanupDatastore(ts.Context)

	page = testEntity.Query().Cache("nodata").MustExecute(ts.GET("/").Request)
	got := page.Data.([]TEntity)
	assert.EqInt(0, len(got))
}
开发者ID:speedland,项目名称:service,代码行数:10,代码来源:query_test.go

示例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")
}
开发者ID:speedland,项目名称:service,代码行数:27,代码来源:query_test.go

示例4: 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")
}
开发者ID:speedland,项目名称:service,代码行数:26,代码来源:delete_test.go

示例5: 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)
}
开发者ID:speedland,项目名称:service,代码行数:26,代码来源:entity_test.go

示例6: 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])
}
开发者ID:speedland,项目名称:service,代码行数:30,代码来源:get_multi_test.go

示例7: 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")
}
开发者ID:speedland,项目名称:service,代码行数:28,代码来源:put_test.go

示例8: 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
}
开发者ID:speedland,项目名称:service,代码行数:31,代码来源:entity_test.go

示例9: 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,
	)
}
开发者ID:speedland,项目名称:service,代码行数:25,代码来源:entity_test.go

示例10: Test_GetWith_Default

func Test_GetWith_Default(t *testing.T) {
	assert := gaetest.NewAssert(t)
	gaetest.CleanupDatastore(ts.Context)

	_, one, err := testEntity.Get().Key("1").UseDefaultIfNil(true).One(ts.GET("/").Request)
	got := one.(*TEntity)
	assert.Nil(err)
	assert.EqStr("1", got.ID, "TEntity.ID")
	assert.EqStr("This is defualt value", got.Desc, "TEntity.Desc")
}
开发者ID:speedland,项目名称:service,代码行数:10,代码来源:get_test.go

示例11: Test_API_Task_Sync

func Test_API_Task_Sync(t *testing.T) {
	assert := gaetest.NewAssert(t)
	gaetest.CleanupDatastore(ts.Context, "hplink")

	httptest.StartMockServer(func(mock *httptest.MockServer) {
		mock.Routes().GET("/", middleware.ServeFile("./fixtures/mocks/helloproject.html"))
		mock.Routes().GET("/c-ute/", middleware.ServeFile("./fixtures/mocks/c-ute/index.html"))
		mock.Routes().GET("/c-ute/*", middleware.StaticFile("", "fixtures/mocks/c-ute/"))

		crawler.MockExternalResource(map[string]string{
			"http://www.helloproject.com/artist/":                             fmt.Sprintf("%s", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/":                       fmt.Sprintf("%sc-ute/", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/profile/maimi_yajima/":  fmt.Sprintf("%sc-ute/maimi_yajima.html", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/profile/saki_nakajima/": fmt.Sprintf("%sc-ute/saki_nkajima.html", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/profile/airi_suzuki/":   fmt.Sprintf("%sc-ute/airi_suzuki.html", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/profile/chisato_okai/":  fmt.Sprintf("%sc-ute/chisato_okai.html", mock.BaseURL()),
			"http://www.helloproject.com/artist/c-ute/profile/mai_hagiwara/":  fmt.Sprintf("%sc-ute/mai_hagiwara.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/profile/", url.Values{})

			p := entities.Artist.Query().Order("Index").MustExecute(ts.GET("/").Request)
			artistList := p.Data.([]hplink.Artist)
			assert.EqInt(1, len(artistList))
			assert.EqInt(0, artistList[0].Index)
			assert.EqStr("c-ute", artistList[0].Key)
			assert.EqStr("℃-ute", artistList[0].Name)

			p = entities.Member.Query().Order("Index").Filter("ArtistKey=", "c-ute").MustExecute(ts.GET("/").Request)
			memberList := p.Data.([]hplink.Member)
			assert.EqInt(5, len(memberList))
			assert.EqInt(0, memberList[0].Index)
			assert.EqStr("c-ute", memberList[0].ArtistKey)
			assert.EqStr("c-ute.maimi_yajima", memberList[0].Key)
			assert.EqStr("矢島舞美", memberList[0].Name)

			entities.FillMemberPublicProfiles(ts.GET("/").Request, memberList)
			assert.NotNil(memberList[0].PublicProfile)
			assert.EqStr("c-ute.maimi_yajima", memberList[0].PublicProfile.Key)
			assert.EqStr("埼玉県", memberList[0].PublicProfile.Hometown)

			_, settings := entities.CrawlerSettings.Get().Key("http://ameblo.jp/c-ute-official").MustOne(ts.GET("/").Request)
			assert.NotNil(settings)
			assert.EqStr("c-ute", settings.(*hplink.CrawlerSettings).ArtistKey)
			assert.EqInt(int(hplink.CrawlerSettingsTypeAmeblo), int(settings.(*hplink.CrawlerSettings).Type))
		})
	})
}
开发者ID:speedland,项目名称:service,代码行数:54,代码来源:api_tasks_test.go

示例12: Test_EntityGet_NotFound

func Test_EntityGet_NotFound(t *testing.T) {
	assert := gaetest.NewAssert(t)
	router := wcg.NewRouter()
	router.GET("/api/:key.json",
		EntityGet(testEntity.Get(), "key"),
	)
	gaetest.CleanupDatastore(ts.Context)

	req := ts.GET("/1.json")
	res := req.RouteTo(router)
	assert.HTTPStatus(404, res)
}
开发者ID:speedland,项目名称:service,代码行数:12,代码来源:entity_test.go

示例13: Test_EntityAll_Empty

func Test_EntityAll_Empty(t *testing.T) {
	assert := gaetest.NewAssert(t)
	router := wcg.NewRouter()
	router.GET("/api/",
		EntityAll(testEntity.Query()),
	)
	gaetest.CleanupDatastore(ts.Context)

	req := ts.GET("/api/")
	res := req.RouteTo(router)
	assert.HTTPStatus(200, res)
	assert.HTTPBodyString("[]", res)
}
开发者ID:speedland,项目名称:service,代码行数:13,代码来源:entity_test.go

示例14: Test_EntityQuery_Empty

func Test_EntityQuery_Empty(t *testing.T) {
	assert := gaetest.NewAssert(t)
	router := wcg.NewRouter()
	router.GET("/api/",
		EntityQuery(testEntity.Query().Limit(2)),
	)
	gaetest.CleanupDatastore(ts.Context)

	var got entities.Pagination
	req := ts.GET("/api/")
	res := req.RouteTo(router)
	assert.HTTPStatus(200, res)
	assert.JSONResponse(&got, res)
	assert.EqInt(0, got.Length())
}
开发者ID:speedland,项目名称:service,代码行数:15,代码来源:entity_test.go

示例15: 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())
}
开发者ID:speedland,项目名称:service,代码行数:15,代码来源:delete_test.go


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