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)) }) }) }
func Test_API_IEPGRecord_OptInOut_Excluded(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_OptInOut.json", nil, "intern.pt"), "fixture") req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "excluded"), url.Values{ "opt_in": []string{"1"}, }) helper.TemporaryAllow(req, "family", func() { var got pt.IEPG res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.OK(got.OptIn, "OptIn") assert.OK(!got.OptOut, "OptOut") }) req = ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "excluded"), url.Values{ "opt_in": []string{"0"}, }) helper.TemporaryAllow(req, "family", func() { var got pt.IEPG res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.OK(!got.OptIn, "OptIn") assert.OK(!got.OptOut, "OptOut") }) }
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)) }) }) }
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)) }) }) }
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"]) }) }
func Test_API_Config_Put(t *testing.T) { assert := gaetest.NewAssert(t) testUser := httptest.NewTestUser().SetID("facebook:12345") dummy := ts.GET("/") configs.TemporarySetConfig(dummy.Request, "facebook_page_id", "12345", func() { messenger.TemporaryOptIn(dummy.Request, "12345", testUser.ID(), func() { var notif pt.MessengerNotification req := ts.PUTForm("/api/intern/pt/configs/facebook%3A12345/messenger.json", url.Values{ "id": []string{"messenger"}, "user_id": []string{"testuser"}, "summary": []string{"true"}, "on_start": []string{"true"}, "on_end": []string{"false"}, }) req.Request.User = testUser helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) assert.JSONResponse(¬if, res) assert.EqStr("testuser", notif.UserID, "MessengerNotification.UserID") assert.OK(notif.Summary, "MessengerNotification.Summary") assert.OK(notif.OnStart, "MessengerNotification.OnStart") assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd") }) }, ) }, ) }
func Test_API_IEPGRecord_Delete(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_Delete.json", nil, "intern.pt"), "fixture") req := ts.DELETE(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg1")) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) }) req = ts.DELETE(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg2")) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(403, res) }) }
func Test_API_Config_Get_Default(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Config_Get.json", nil), "fixture") testUser := httptest.NewTestUser().SetID("facebook:6789") dummy := ts.GET("/") configs.TemporarySetConfig(dummy.Request, "facebook_page_id", "12345", func() { messenger.TemporaryOptIn(dummy.Request, "12345", testUser.ID(), func() { var notif pt.MessengerNotification req := ts.GET("/api/intern/pt/configs/facebook%3A6789/messenger.json") req.Request.User = testUser helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) assert.JSONResponse(¬if, res) assert.EqStr("facebook:6789", notif.UserID, "MessengerNotification.UserID") assert.OK(!notif.Summary, "MessengerNotification.Summary") assert.OK(!notif.OnStart, "MessengerNotification.OnStart") assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd") }) }, ) }, ) }
func Test_API_IEPGExclusion_Delete(t *testing.T) { assert := gaetest.NewAssert(t) req := ts.DELETE("/api/intern/pt/channels/test1.json") helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) }) }
func Test_API_CrawlerSettings_Delete(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_CrawlerSettings_Delete.json", nil, "hplink"), "fixture") req := ts.DELETE("/api/hplink/crawlersettings/http%3A%2F%2Fameblo.jp%2Fc-ute-official%2F.json") testhelper.TemporaryAllow(req, "hplink.admin", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) _, settings := entities.CrawlerSettings.Get().Key("http://ameblo.jp/c-ute-official/").MustOne(ts.GET("/").Request) assert.Nil(settings) }) }
func Test_API_IEPGRecord_OptInOut_NonAutoCollected(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_OptInOut.json", nil, "intern.pt"), "fixture") req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "iepg1"), url.Values{ "opt_in": []string{"1"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(400, res) }) }
func Test_API_IEPGExclusion_RunTask(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGExclusion_RunTask.json", nil, "intern.pt")) now, _ := wcg.ParseDateTime("2016-01-01T00:00:00Z") lib.TemporarySetNow(now, func() { runner := helper.NewAsyncTaskTestRunner(t, instance.Routes(), ts) runner.OnTrigger(func(req *httptest.TestRequest, trigger func()) { helper.TemporaryAllow(req, "family", trigger) }) runner.OnMonitor(func(req *httptest.TestRequest, monitor func()) { helper.TemporaryAllow(req, "family", monitor) }) runner.Run("/api/intern/pt/iepg/exclusions/task/", url.Values{}) req := ts.GET("/dummy") _, flagged := IEPG.Get().Key("test1").MustOne(req.Request) assert.OK(len(flagged.(*pt.IEPG).ExcludedBy) > 0) }) }
func Test_API_Config_Get_NoPageIDConfigured(t *testing.T) { assert := gaetest.NewAssert(t) dummy := ts.GET("/") configs.TemporarySetConfig(dummy.Request, "facebook_page_id", "", func() { req := ts.GET("/api/intern/pt/configs/facebook%3A12345/messenger.json") helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(403, res) }) }, ) }
func Test_API_IEPGRecord_Put(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_Put.json", nil, "intern.pt"), "fixture") req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg1"), url.Values{ "program_title": []string{"Test Program"}, "start_at": []string{"2015-01-01T19:00:00.000Z"}, "end_at": []string{"2015-01-01T19:00:00.000Z"}, "category": []string{"test"}, "cid": []string{"21"}, "sid": []string{"aa"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) var got pt.IEPG assert.JSONResponse(&got, res) assert.EqStr("Test Program", got.ProgramTitle, "program_title") assert.EqStr("21", got.CID, "CID") assert.EqStr("aa", got.SID, "SID") assert.EqInt(int(pt.IEPGSourceUser), int(got.Source), "Source") }) req = ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg2"), url.Values{ "program_title": []string{"Test Program"}, "start_at": []string{"2015-01-01T19:00:00.000Z"}, "end_at": []string{"2015-01-01T19:00:00.000Z"}, "category": []string{"test"}, "cid": []string{"21"}, "sid": []string{"aa"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(403, res) }) }
func Test_API_IEPGKeyword_Post(t *testing.T) { assert := gaetest.NewAssert(t) req := ts.POSTForm("/api/intern/pt/iepg/keywords/", url.Values{ "keyword": []string{"テストキーワード"}, "scope": []string{"1"}, "category": []string{"カテゴリ"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(201, res) var got pt.IEPGKeyword assert.JSONResponse(&got, res) assert.EqStr("テストキーワード", got.Keyword, "IEPGKeyword.Keyword") }) }
func Test_API_Config_Get_NoOptIn(t *testing.T) { assert := gaetest.NewAssert(t) testUser := httptest.NewTestUser().SetID("facebook:12345") dummy := ts.GET("/") configs.TemporarySetConfig(dummy.Request, "facebook_page_id", "12345", func() { req := ts.GET("/api/intern/pt/configs/facebook%3A12345/messenger.json") req.Request.User = testUser helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(403, res) }) }, ) }
func Test_API_CrawlerSettings_Update(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_CrawlerSettings_Update.json", nil, "hplink"), "fixture") req := ts.PUTForm("/api/hplink/crawlersettings/http%3A%2F%2Fameblo.jp%2Fc-ute-official%2F.json", url.Values{ "artist_key": []string{"c-ute"}, }) testhelper.TemporaryAllow(req, "hplink.admin", func() { res := req.RouteTo(instance.Routes()) var got hplink.CrawlerSettings assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.EqStr("http://ameblo.jp/c-ute-official/", got.URL) assert.EqStr("c-ute", got.ArtistKey) _, settings := entities.CrawlerSettings.Get().Key("http://ameblo.jp/c-ute-official/").MustOne(ts.GET("/").Request) assert.NotNil(settings) }) }
func Test_API_Channel_Post(t *testing.T) { assert := gaetest.NewAssert(t) req := ts.POSTForm("/api/intern/pt/channels/", url.Values{ "cid": []string{"123"}, "sid": []string{"hd"}, "name": []string{"My Channel"}, "iepg_station_id": []string{"D12345"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(201, res) var got pt.Channel assert.JSONResponse(&got, res) assert.EqStr("123.hd", got.ID, "Channel.ID") }) }
func Test_API_IEPGExclusion_Post(t *testing.T) { assert := gaetest.NewAssert(t) req := ts.POSTForm("/api/intern/pt/iepg/exclusions/", url.Values{ "cid": []string{"123"}, "sid": []string{"my station"}, "weekday": []string{"0"}, "title_text": []string{"mytitle"}, "title_text_type": []string{"2"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(201, res) var got pt.IEPGExclusion assert.JSONResponse(&got, res) assert.EqStr("123", got.CID, "IEPGExclusion.CID") }) }
func Test_Gate(t *testing.T) { assert := gaetest.NewAssert(t) router := wcg.NewRouter() router.GET("/", Gate("foo"), 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("/") testhelper.TemporaryAllow(req, "foo", func() { res := req.RouteTo(router) assert.HTTPStatus(200, res) }) }
func Test_API_Artist_Member_Update(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Artist_Member_Update.json", nil, "hplink"), "fixture") req := ts.PUTForm("/api/hplink/c-ute/members/maimi_yajima.json", url.Values{ "generation": []string{"1"}, "color": []string{"#ff0000"}, }) testhelper.TemporaryAllow(req, "hplink.admin", func() { res := req.RouteTo(instance.Routes()) var got hplink.Member assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.EqStr("c-ute.maimi_yajima", got.Key) assert.EqInt(1, got.Generation) assert.EqStr("#ff0000", got.Color.ToHexString()) assert.EqTime(time.Time{}, got.Graduationday) _, member := entities.Member.Get().Key("c-ute.maimi_yajima").MustOne(ts.GET("/").Request) assert.NotNil(member) assert.EqStr("#ff0000", member.(*hplink.Member).Color.ToHexString()) }) }
func Test_API_IEPGRecord_Post(t *testing.T) { assert := gaetest.NewAssert(t) req := ts.POSTForm("/api/intern/pt/iepg/records/", url.Values{ "program_title": []string{"Test Program"}, "start_at": []string{"2015-01-01T19:00:00.000Z"}, "end_at": []string{"2015-01-01T19:00:00.000Z"}, "category": []string{"test"}, "cid": []string{"27"}, "sid": []string{"hd"}, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(201, res) var got pt.IEPG assert.JSONResponse(&got, res) assert.EqStr("Test Program", got.ProgramTitle, "program_title") assert.EqStr("27", got.CID, "CID") assert.EqStr("hd", got.SID, "SID") assert.EqInt(int(pt.IEPGSourceUser), int(got.Source), "Source") }) }
func Test_API_IEPGKeyword_Crawl_Preview(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetMemcache(ts.Context)) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGKeyword_Crawl.json", nil, "intern.pt"), "fixture") httptest.StartMockServer(func(mock *httptest.MockServer) { // preparation for dummy entry mock.Routes().GET("/*", middleware.StaticFile("", "./fixtures/mocks/")) // Preview Ttest req := ts.POSTForm("/api/intern/pt/iepg/keywords/preview/", url.Values{ "keyword": []string{"テスト"}, "scope": []string{"0"}, }) var feedIDs []string req.Request.SetLocal("__test_iepg_url_resolver", &iepgURLResolver{ getFeedURL: func(keyword string, scope pt.IEPGCrawlerScope) string { assert.EqStr("テスト", keyword, "keyword") assert.EqInt(int(pt.IEPGCrawlerScopeAll), int(scope), "scope") return fmt.Sprintf( "%s/feed/feed.rss", mock.BaseURL(), ) }, getDataURL: func(id string) string { feedIDs = append(feedIDs, id) return fmt.Sprintf( "%s/data/%s.txt", mock.BaseURL(), id, ) }, }) helper.TemporaryAllow(req, "family", func() { res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) assert.EqInt(4, len(feedIDs), "collected Feed IDs") assert.EqStr("succ", feedIDs[0], "feedIDs[0]") assert.EqStr("opted-out", feedIDs[1], "feedIDs[1]") assert.EqStr("excluded", feedIDs[2], "feedIDs[2]") assert.EqStr("multiple-categories", feedIDs[3], "feedIDs[3]") var got map[string][]pt.IEPG assert.JSONResponse(&got, res) assert.EqInt(4, len(got["hits"]), "len(got[\"hits\"])") var hits = got["hits"] var succ = hits[0] var optout = hits[1] var excluded = hits[2] var multiplecategories = hits[3] // assertion for succ assert.EqStr("DFS00430", succ.StationID, "succ.StationID") assert.EqStr("テレビ東京", succ.StationName, "succ.StationName") assert.EqStr( "The\u3000Girls\u3000Live\u3000▽道重さゆみ卒業ライブに密着▽LoVendoЯスタジオライブ", succ.ProgramTitle, "succ.ProgramTitle", ) assert.EqInt(2014, succ.StartAt.Year(), "succ.StartAt.Year()") assert.EqInt(12, int(succ.StartAt.Month()), "succ.StartAt.Month()") assert.EqInt(5, succ.StartAt.Day(), "succ.StartAt.Day()") assert.EqInt(23, succ.StartAt.Hour(), "succ.StartAt.Hour()") assert.EqInt(0, succ.StartAt.Minute(), "succ.StartAt.Minute()") assert.EqInt(2014, succ.EndAt.Year(), "succ.EndAt.Year()") assert.EqInt(12, int(succ.EndAt.Month()), "succ.EndAt.Month()") assert.EqInt(6, succ.EndAt.Day(), "succ.EndAt.Day()") assert.EqInt(1, succ.EndAt.Hour(), "succ.EndAt.Hour()") assert.EqInt(30, succ.EndAt.Minute(), "succ.EndAt.Minute()") assert.EqStr("23", succ.CID, "succ.CID") assert.EqStr("hd", succ.SID, "succ.SID") assert.Not(succ.OptIn, "succ.OptIn") assert.Not(succ.OptOut, "succ.OptOut") assert.EqInt(0, len(succ.ExcludedBy), "len(succ.ExcludedBy)") assert.EqInt(0, len(succ.CrawledBy), "len(succ.CrawledBy)") // assertion for optout assert.Not(optout.OptIn, "OptIn") assert.OK(optout.OptOut, "OptOut") assert.EqInt(0, len(optout.ExcludedBy), "len(ExcludedBy)") // assertion for excluded assert.Not(excluded.OptIn, "excluded.OptIn") assert.Not(excluded.OptOut, "excluded.OptOut") assert.EqInt(1, len(excluded.ExcludedBy), "len(excluded.ExcludedBy)") assert.EqStr("crawl-test-exclusion", excluded.ExcludedBy[0], "excluded.ExcludedBy[0]") // assertion for multiple categories. assert.EqInt(1, len(multiplecategories.CrawledBy), "len(multiplecategories.CrawledBy)") assert.EqStr("another-crawl-keyword", multiplecategories.CrawledBy[0], "multiplecategories.CrawledBy[0]") }) }) }