func TestObjectValidation(t *testing.T) { type TestObject struct { Str1 string Str2 string } assert := wcg.NewAssert(t) obj := &TestObject{} v := NewObjectValidator() v.Func(func(v interface{}) *FieldValidationError { obj := v.(*TestObject) if obj.Str1 == obj.Str2 { return NewFieldValidationError( "Same!!", nil, ) } return nil }) obj.Str1 = "foo" obj.Str2 = "foo" result := v.Eval(obj).(*ValidationError) assert.NotNil(result.Errors["."], "ValidationError should claims on 'Str'") assert.EqStr("Same!!", result.Errors["."][0].String(), "ValidationError Error message") obj.Str2 = "bar" assert.Nil(v.Eval(obj), "Eval(obj) should return nil when validation passed.") }
func TestRecorderStart_CancelBeforeStart(t *testing.T) { assert := wcg.NewAssert(t) receiver := make(chan []Record) recorder := NewRecorder((<-chan []Record)(receiver)) interval := time.Duration(30) * time.Millisecond wait := 10 go recorder.Start(interval) now := time.Now() r1 := NewDummyRecord("r1") // cancel before starting r1.startAt = now.Add(time.Duration(30 * time.Minute)) r1.endAt = now.Add(time.Duration(60 * time.Minute)) // r2 := NewDummyRecord("r2") // cancel after starting // r3 := NewDummyRecord("r3") // succeeded // r4 := NewDummyRecord("r4") // failed receiver <- []Record{r1} err := util.WaitFor(func() bool { return len(recorder.controls) == 1 }, wait) assert.Nil(err, "check r1 in controls.") assert.EqStr(r1.Key(), recorder.controls[r1.Key()].record.Key(), "check r1 in controls.") receiver <- []Record{} err = util.WaitFor(func() bool { return len(recorder.controls) == 0 }, wait) assert.Nil(err, "check r1 removed from controls.") recorder.Stop() }
func TestRecordValidator(t *testing.T) { var err error assert := wcg.NewAssert(t) r := genTestRecord() r.Title = "" err = RecordValidator.Eval(r) assert.NotNil(err, "Empty Title Error") r.Title = "../foo" err = RecordValidator.Eval(r) assert.NotNil(err, "Special Character Validation") r.Title = "NormalTitle" err = RecordValidator.Eval(r) assert.Nil(err, "Normal Character Validation") r.Title = "日本語はつかえる" err = RecordValidator.Eval(r) assert.Nil(err, "日本語 Validation") r.Title = "モーニング娘。" err = RecordValidator.Eval(r) assert.Nil(err, "日本語 特殊文字 Valiation") }
func TestRecorderStart(t *testing.T) { assert := wcg.NewAssert(t) receiver := make(chan []Record) recorder := NewRecorder((<-chan []Record)(receiver)) interval := time.Duration(30) * time.Millisecond wait := 10 go recorder.Start(interval) now := time.Now() r1 := NewDummyRecord("r1") // cancel before starting r1.startAt = now r1.endAt = now.Add(time.Duration(5 * time.Second)) receiver <- []Record{r1} err := util.WaitFor(func() bool { return len(recorder.controls) == 1 }, wait) assert.Nil(err, "check r1 in controls.") ctrl := recorder.controls[r1.Key()] err = util.WaitFor(func() bool { return r1.done == true }, wait) assert.Nil(err, "check r1 has been done.") assert.EqInt(int(RSSucceeded), int(ctrl.state), "Record state should be RSSucceeded") recorder.Stop() }
func TestPt1Record_Start(t *testing.T) { assert := wcg.NewAssert(t) now := time.Now() tvrecord := models.NewTvRecord( "Title", "Category", now, now.Add(time.Duration(5)*time.Second), "cid", "sid", "uid", ) util.WithTempDir(func(dir string) { record := NewPt1Record(tvrecord, genPt1Config(dir)) err := record.Start() assert.Nil(err, "Pt1Record started.") time.Sleep(1 * time.Second) assert.Ok(record.IsRunning(), "Pt1Record is running.") err = record.Stop() assert.Nil(err, "Stop record.") err = util.WaitFor(func() bool { return record.IsRunning() == false }, 10) assert.Nil(err, "Pt1Record has stopped.") content, _ := ioutil.ReadFile(record.filepath) lines := bytes.Split(content, []byte("\n")) assert.EqStr("OK", string(lines[len(lines)-1]), "Check the mock record content.") }) }
func TestGetIEpgList(t *testing.T) { assert := wcg.NewAssert(t) client := NewCrawler(http.DefaultClient) list, err := client.GetIEpgList("今井絵理子", FEED_SCOPE_ALL) assert.Nil(err, "GetIEpgList should not return an error.") assert.NotNil(list, "GetIEpgList should return list of ids") }
func TestChannel_AddAndDelCrawlerConfig(t *testing.T) { test.RunTestServer(func(ts *test.TestServer) { assert := wcg.NewAssert(t) // prepare d := NewCrawlerConfigDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil)) d.Add(&tv.CrawlerConfig{ Keyword: "キーワード1", Category: "カテゴリー1", Scope: 1, }) d.Add(&tv.CrawlerConfig{ Keyword: "キーワード2", Category: "カテゴリー2", Scope: 1, }) err := util.WaitFor(func() bool { c, _ := d.NewQuery().Count() return c == 2 }, util.DefaultWaitForTimeout) assert.Nil(err, "Confirm CrawlerConfig entities has been stored within a timeout window.") d.Delete("キーワード1") err = util.WaitFor(func() bool { c, _ := d.NewQuery().Count() return c == 1 }, util.DefaultWaitForTimeout) assert.Nil(err, "Confirm CrawlerConfig entities has been deleted within a timeout window.") err = d.Delete("Not Exists") assert.Nil(err, "Delete should not return even trying to delete the unexising keyword.") }) }
func TestIOLogSinkFormat(t *testing.T) { assert := wcg.NewAssert(t) record := NewTestRecord() storage := NewTestLogStorage() s := NewIOLogSink("", storage) s.Write(record) assert.NotZero(len(storage.GetLines()), "sink.Write should write a log record") line := storage.GetLines()[0] expect := "1984/09/22 12:01:28 +0000 [TRACE] [1|user1|session1|request1] This is a test (sourec.go#1)" assert.EqStr(expect, line, "LogRecord format") // custom format storage = NewTestLogStorage() s = NewIOLogSink("$TIMESTAMP $INVALIDVAR $TEXT", storage) s.Write(record) assert.NotZero(len(storage.GetLines()), "sink.Write should write a log record") line = storage.GetLines()[0] expect = "1984/09/22 12:01:28 +0000 This is a test" assert.EqStr(expect, line, "LogRecord format") // Data record case. storage = NewTestLogStorage() s = NewIOLogSink("", storage) record.Data = wcg.DataBag{} s.Write(record) assert.Zero(len(storage.GetLines()), "sink.Write should not write anything if the record has DataBag") }
func TestRecorderUpcomming(t *testing.T) { assert := wcg.NewAssert(t) receiver := make(chan []Record) recorder := NewRecorder((<-chan []Record)(receiver)) interval := time.Duration(30) * time.Millisecond wait := 10 go recorder.Start(interval) r1 := NewDummyRecord("r1") r1.startAt = time.Now().Add(time.Duration(2 * time.Hour)) r1.endAt = r1.startAt.Add(time.Duration(10 * time.Minute)) r2 := NewDummyRecord("r2") r2.startAt = time.Now().Add(time.Duration(4 * time.Hour)) r2.endAt = r2.startAt.Add(time.Duration(10 * time.Minute)) r3 := NewDummyRecord("r3") r3.startAt = time.Now().Add(time.Duration(8 * time.Hour)) r3.endAt = r3.startAt.Add(time.Duration(10 * time.Minute)) receiver <- []Record{r1, r2, r3} err := util.WaitFor(func() bool { return len(recorder.controls) == 3 }, wait) assert.Nil(err, "check all records in controls.") upcome := recorder.Upcomming() assert.Ok(r1.startAt.Equal(upcome), "Upcomming should be r2") recorder.Stop() }
func TestRecorderStart_CancelWhileRecording(t *testing.T) { assert := wcg.NewAssert(t) receiver := make(chan []Record) recorder := NewRecorder((<-chan []Record)(receiver)) interval := time.Duration(30) * time.Millisecond wait := 5 go recorder.Start(interval) now := time.Now() r1 := NewDummyRecord("r1") // cancel before starting r1.startAt = now r1.endAt = now.Add(time.Duration(30 * time.Minute)) receiver <- []Record{r1} err := util.WaitFor(func() bool { return len(recorder.controls) == 1 }, wait) assert.Nil(err, "check r1 in controls.") assert.EqStr(r1.Key(), recorder.controls[r1.Key()].record.Key(), "check r1 in controls.") err = util.WaitFor(func() bool { return recorder.controls[r1.Key()].state == RSRecording }, wait) assert.Nil(err, "check r1 in RSRecording state.") receiver <- []Record{} err = util.WaitFor(func() bool { return len(recorder.controls) == 0 }, wait) assert.Nil(err, "check r1 removed from controls.") recorder.Stop() }
func Test_parseAuctionApiResult(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./auction-sample.xml") defer file.Close() auction, err := parseAuctionApiResult(file) assert.Nil(err, "parseAuctionApiResult should not return an error") assert.EqStr("h206483716", auction.Id, "Id") assert.EqStr("9/20 モーニング娘。15 座間 秋ツアー 夜公演 一般席 即決特典付", auction.Title, "Title") assert.EqStr("http://page8.auctions.yahoo.co.jp/jp/auction/h206483716", auction.Url, "Url") assert.EqStr("", auction.ImageUrl, "ImageUrl") assert.EqStr("gaba9tmcy2gam0", auction.Seller, "Seller") assert.EqFloat32(9000.0, auction.InitPrice, "InitPrice") assert.EqFloat32(9500.0, auction.CurrentPrice, "CurrentPrice") assert.EqFloat32(13000.0, auction.BidOrBuy, "BidOrBuy") assert.EqFloat32(13000.0, auction.BidOrBuy, "BidOrBuy") assert.EqInt(1, auction.Quantity, "Quantity") assert.EqInt(3, auction.Bids, "Bids") assert.EqTime( wcg.Must(time.Parse(time.RFC3339, "2015-08-30T20:27:57+09:00")).(time.Time), auction.StartAt, "StartAt", ) assert.EqTime( wcg.Must(time.Parse(time.RFC3339, "2015-08-31T23:27:57+09:00")).(time.Time), auction.EndAt, "EndAt", ) assert.Ok( STATUS_CLOSED == auction.Status, "Closed", ) }
func TestTwitterClient_Stream(t *testing.T) { assert := wcg.NewAssert(t) NUM_TWEETS_IN_STREAM := 5 httptest.StartMockServer("./dummy", func(ms *httptest.MockServer) { ms.Routes().Get("/1.1/statuses/filter.json", func(res *wcg.Response, req *wcg.Request) { data, _ := json.Marshal(map[string]interface{}{ "id_str": "123", "text": "test text", "created_at": "Thu Sep 24 13:26:59 +0000 2015", }) for i := 0; i < NUM_TWEETS_IN_STREAM; i++ { res.WriteString(string(data) + "\r\n") res.WriteString("\r\n") // send empty (optional) res.Flush() time.Sleep(10 * time.Millisecond) } res.Close() }) client := NewTwitterClient("", "", nil) client.StreamingEndpoint = ms.BaseUrl() client.Token = BearerToken("TestToken") ts, err := client.Stream(&StreamingParams{}) assert.Nil(err, "Stream should not return an error") var tweet *Tweet ch := ts.GetStreamChannel() num_received := 0 for tweet = range ch { num_received += 1 } assert.EqInt(NUM_TWEETS_IN_STREAM+1, num_received, "The number of tweets is incorrect.") assert.Nil(tweet, "The end of stream should be nil") }) }
func TestParseIEpg(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./iepg-sample.iepg") defer file.Close() iepg, err := ParseIEpg(file) assert.Nil(err, "ParseIEPG should not return an error") assert.EqStr("The Girls Live ▽道重さゆみ卒業ライブに密着▽LoVendoЯスタジオライブ", iepg.ProgramTitle, "ProgramTitle") assert.EqStr("テレビ東京", iepg.StationName, "StationName") assert.EqStr("DFS00430", iepg.StationId, "StationId") assert.EqInt(7852, iepg.ProgramId, "ProgramId") assert.EqInt(2014, iepg.StartAt.Year(), "StartAt.Year") assert.EqInt(12, int(iepg.StartAt.Month()), "StartAt.Date") assert.EqInt(5, iepg.StartAt.Day(), "StartAt.Date") assert.EqInt(1, iepg.StartAt.Hour(), "StartAt.Hour") assert.EqInt(0, iepg.StartAt.Minute(), "StartAt.Mininute") zone, _ := iepg.StartAt.Zone() assert.EqStr("JST", zone, "StartAt.Zone") assert.EqInt(2014, iepg.EndAt.Year(), "EndAt.Year") assert.EqInt(12, int(iepg.EndAt.Month()), "EndAt.Date") assert.EqInt(5, iepg.EndAt.Day(), "EndAt.Date") assert.EqInt(1, iepg.EndAt.Hour(), "EndAt.Hour") assert.EqInt(30, iepg.EndAt.Minute(), "EndAt.Mininute") zone, _ = iepg.EndAt.Zone() assert.EqStr("JST", zone, "EndAt.Zone") }
func TestMax(t *testing.T) { type TestObject struct { Str string Int int Float float32 Array []string } assert := wcg.NewAssert(t) obj := &TestObject{} v := NewObjectValidator() v.Field("Str").Max(1) v.Field("Int").Max(1) v.Field("Float").Max(1) v.Field("Array").Max(1) obj.Str = "Foo" obj.Int = 5 obj.Float = 5 obj.Array = []string{"a", "b", "c", "d"} result := v.Eval(obj).(*ValidationError) assert.NotNil(result.Errors["Str"], "ValidationError should claims on 'Str'") assert.NotNil(result.Errors["Int"], "ValidationError should claims on 'Int'") assert.NotNil(result.Errors["Float"], "ValidationError should claims on 'Float'") assert.NotNil(result.Errors["Array"], "ValidationError should claims on 'Arrau'") assert.EqStr("must be less than or equal to 1", result.Errors["Str"][0].String(), "ValidationError Error message") assert.EqStr("must be less than or equal to 1", result.Errors["Int"][0].String(), "ValidationError Error message") assert.EqStr("must be less than or equal to 1", result.Errors["Float"][0].String(), "ValidationError Error message") assert.EqStr("must be less than or equal to 1", result.Errors["Array"][0].String(), "ValidationError Error message") obj.Str = "F" obj.Int = 1 obj.Float = 1 obj.Array = []string{"a"} assert.Nil(v.Eval(obj), "Eval(obj) should return nil when validation passed.") }
func TestMatch(t *testing.T) { type TestObject struct { Str string Bytes []byte } assert := wcg.NewAssert(t) obj := &TestObject{} v := NewObjectValidator() v.Field("Str").Match("a+") v.Field("Bytes").Match("a+") result := v.Eval(obj).(*ValidationError) assert.NotNil(result.Errors["Str"], "ValidationError should claims on 'Str'") assert.NotNil(result.Errors["Bytes"], "ValidationError should claims on 'Bytes'") assert.EqStr("not match with 'a+'", result.Errors["Str"][0].String(), "ValidationError Error message") assert.EqStr("not match with 'a+'", result.Errors["Bytes"][0].String(), "ValidationError Error message") obj.Str = "bbb" obj.Bytes = []byte(obj.Str) result = v.Eval(obj).(*ValidationError) assert.NotNil(result, "Eval(obj) should return ValidationError") assert.NotNil(result.Errors["Str"], "ValidationError should claims on 'Str'") assert.NotNil(result.Errors["Bytes"], "ValidationError should claims on 'Bytes'") assert.EqStr("not match with 'a+'", result.Errors["Str"][0].String(), "ValidationError Error message") assert.EqStr("not match with 'a+'", result.Errors["Bytes"][0].String(), "ValidationError Error message") obj.Str = "aaa" obj.Bytes = []byte(obj.Str) assert.Nil(v.Eval(obj), "Eval(obj) should return nil when validation passed.") }
func TestParseEntry(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./entry-sample.html") defer file.Close() entry, err := ParseEntry(file) assert.Nil(err, "ParseEntryContent should not return an error") assert.EqStr("早くヴァンプになりた〜い!工藤 遥", entry.Title, "Title") }
func TestGetOverlaps(t *testing.T) { test.RunTestServer(func(ts *test.TestServer) { var found []*tv.TvRecord const timeForm = "2006/01/02 15:04:05" assert := wcg.NewAssert(t) d := NewTvRecordDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil)) base := genTestRecord() base.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:00:00") base.EndAt, _ = time.Parse(timeForm, "2014/01/01 13:00:00") d.Save(base) err := util.WaitFor(func() bool { c, _ := d.NewQuery().Count() return c == 1 }, util.DefaultWaitForTimeout) assert.Nil(err, "Confirm TvRecord entities has been stored within a timeout window.") // case1: no overlaps r := genTestRecord() r.StartAt, _ = time.Parse(timeForm, "2014/01/01 10:50:00") r.EndAt, _ = time.Parse(timeForm, "2014/01/01 11:10:00") found, err = d.GetOverlaps(r) assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case1)") assert.EqInt(0, len(found), "TvRecordDriver#GetOverlaps should return empty array (case1)") // case 2: base.end < r.start r = genTestRecord() r.StartAt, _ = time.Parse(timeForm, "2014/01/01 13:50:00") r.EndAt, _ = time.Parse(timeForm, "2014/01/01 14:10:00") found, err = d.GetOverlaps(r) assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case2)") assert.EqInt(0, len(found), "TvRecordDriver#GetOverlaps should return empty array (case2)") // case 3: base.start < r.start < base.end r = genTestRecord() r.StartAt, _ = time.Parse(timeForm, "2014/01/01 11:50:00") r.EndAt, _ = time.Parse(timeForm, "2014/01/01 12:10:00") found, err = d.GetOverlaps(r) assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case3)") assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case3)") // case 4: r.start < base.end < r.end r = genTestRecord() r.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:50:00") r.EndAt, _ = time.Parse(timeForm, "2014/01/01 13:10:00") found, err = d.GetOverlaps(r) assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case4)") assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case4)") // case 5: r.start < base.start < base.end < r.end r = genTestRecord() r.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:10:00") r.EndAt, _ = time.Parse(timeForm, "2014/01/01 12:50:00") found, err = d.GetOverlaps(r) assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case4)") assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case4)") }) }
func TestCrawlEntry(t *testing.T) { assert := wcg.NewAssert(t) c := &Crawler{ http.DefaultClient, } entry, err := c.CrawlEntry("http://ameblo.jp/sayumimichishige-blog/entry-11874881676.html") assert.Nil(err, "CrawlEntryList should not return an error") assert.EqStr("春ツアー思い出", entry.Title, "An entry in EntryList should have title.") }
func TestCrawlEntryList(t *testing.T) { assert := wcg.NewAssert(t) c := &Crawler{ http.DefaultClient, } list, err := c.CrawlEntryList("http://ameblo.jp/sayumimichishige-blog/entrylist.html") assert.Nil(err, "CrawlEntryList should not return an error") assert.Ok(len(list) > 0, "CrawlEntryList should return some entries.") assert.Ok(list[0].Title != "", "An entry in EntryList should have title.") }
func TestSign(t *testing.T) { assert := wcg.NewAssert(t) cmd := "sign foo" stdout := ExecToolEx(cmd) assert.EqStr(wcg.Sign("foo", "wcgsess")+"\n", stdout, cmd) cmd = "sign -k bar foo" stdout = ExecToolEx(cmd) assert.EqStr(wcg.Sign("foo", "bar")+"\n", stdout, cmd) }
func Test_parseClosedSearchResult(t *testing.T) { assert := wcg.NewAssert(t) file, err := os.Open("./closed-search-sample.html") defer file.Close() list, hasMore, err := parseClosedSearchResult(file) assert.Nil(err, "parseSearchResult should not return an error") assert.EqInt(100, len(list), "parseClosedSearchResult should return 10 ids.") assert.Ok(hasMore, "parseClosedSearchResult should return true for hasMore flag.") }
func TestGetDescription(t *testing.T) { assert := wcg.NewAssert(t) ent := &AmebloEntry{} ent.Content = `<div class="articleText"> <!-- google_ad_section_start(name=s1, weight=.9) --> <span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">こんばんぽ(*'∀'*)ノん</span><img src="http://emoji.ameba.jp/img/user/mi/misaki0309/445.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>えりぽんにずっとご飯食べに行こ~って誘われてたのが今朝実現しました~♪♪♪<br/><br/>お仕事の時間とかの調整で<br/>朝ごはんに!</span><img src="http://emoji.ameba.jp/img/user/sa/saeko-eight/2621.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/></span><div id="{45CC107C-5344-4B66-99FA-DC3E2B0D45A2:01}" style="text-align:left"><div align="left"><a id="i13203104843" class="detailOn" href="http://ameblo.jp/morningmusume-9ki/image-11983243084-13203104843.html"><img src="http://stat.ameba.jp/user_images/20150129/23/morningmusume-9ki/cc/1d/j/o0480036013203104843.jpg" alt="{45CC107C-5344-4B66-99FA-DC3E2B0D45A2:01}" width="300" height="225" border="0"/></a></div></div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">サラダを頼んだんですけど…<br/>えりぽんこれ食べられるの?!ってくらい結構量が多くて!<br/><br/>聖はサラダ大好きだから余裕だったんですけどね( ̄ー+ ̄*)キラーン</span><img src="http://emoji.ameba.jp/img/user/ch/chisono200/1075.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>野菜嫌いのえりぽんがきゅうり以外全部食べましたよ</span><img src="http://emoji.ameba.jp/img/user/s0/s0111012/3582.gif"/><img src="http://emoji.ameba.jp/img/user/s0/s0111012/3582.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>えらい!というか凄いですよね!<br/><br/>きゅうりは聖が食べました(笑<br/><br/>そしてお昼は里保ちゃんとアサイーを食べに</span><img src="http://emoji.ameba.jp/img/user/ha/ha-ke-li-7/511.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/>前に道重さんとはるなんと3人で行ったことある所です</span><img src="http://emoji.ameba.jp/img/user/s0/s0111012/6933.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/></span><div id="{41FBED6C-60E2-4C86-8C96-871C9B470D9E:01}" style="text-align:left"><div align="left"><a id="i13203104869" class="detailOn" href="http://ameblo.jp/morningmusume-9ki/image-11983243084-13203104869.html"><img src="http://stat.ameba.jp/user_images/20150129/23/morningmusume-9ki/d3/b8/j/o0480036013203104869.jpg" alt="{41FBED6C-60E2-4C86-8C96-871C9B470D9E:01}" width="300" height="225" border="0"/></a></div></div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">いぇ~い</span><img src="http://emoji.ameba.jp/img/user/hi/high-high-naka-ta/672.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/>里保ちゃんここのお店のアサイー食べるの初めてだったみたいで絶賛していました!<br/>レギュラー頼んでたのにもう一個いけるって!</span><img src="http://emoji.ameba.jp/img/user/mo/moyu-moyu/1013.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>また一緒に行こうね~<br/><br/></span><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><div>なんか今日食べてばっか?</div><div>今日のご飯これでおしまーーい</div><br/><br/>そーしーてー!<br/><br/>『アオハルーーーーー!!!』<br/><br/>叫びたくなりますね!!!<br/>なんか、題名通りですけど青春感じました♪♪♪<br/><br/></span><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">ママと行ったんですけど、なんか恥ずかしくなりました</span><img src="http://emoji.ameba.jp/img/user/mi/mikankko/264.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>漫画も読んでたし、メンバーにもオススメされてたからどうしても行きたかったんです</span><img src="http://emoji.ameba.jp/img/user/31/3141592/16928.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>行けて良かった~<br/>映画で恋愛ストーリー観たの初めてでした</span><img src="http://emoji.ameba.jp/img/user/w9/w921k903-tb-smile/1520.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>あっ!ちゃんとお仕事もしてきましたからね!</span><img src="http://emoji.ameba.jp/img/user/sa/saeko-eight/2621.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>合間の時間を有意義に使えて嬉しかったな♪</span><div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/></span></div><div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>今日ね~、<br/><br/>この前の服より今日の服の方が好き!ってマネージャーさんが</span><img src="http://emoji.ameba.jp/img/user/mi/misaki0309/445.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/>譜久村成長しました~</span><img src="http://emoji.ameba.jp/img/user/s0/s0111012/6912.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>写真は忘れましたーm(_ _)m</span><img src="http://emoji.ameba.jp/img/user/so/soukou/6087.gif"/><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br/><br/>おやすみずき</span><img src="http://emoji.ameba.jp/img/user/s0/s0111012/4490.gif"/><img src="http://emoji.ameba.jp/img/user/s0/s0111012/4337.gif"/></div> <!-- google_ad_section_end(name=s1) --> </div>` s, _ := ent.GetDescription() assert.EqStr( "こんばんぽ(*'∀'*)ノんえりぽんにずっとご飯食べに行こ~って誘われてたのが今朝実現しました~♪♪♪お仕事の時間とかの調整で朝ごはんに!サラダを頼んだんですけど…えりぽんこれ食べられるの?!ってくらい結構量が多くて!聖はサラダ大好きだから余裕だったんですけどね( ̄ー+ ̄*)キラ...", s, "GetDescription()", ) }
func TestGetExternalPath(t *testing.T) { assert := wcg.NewAssert(t) page := &Page{} page.App = NewApp("default", "dummy") page.Path = "/path/to/foo" assert.EqStr("/default/path/to/foo/", page.GetExternalPath(), "GetExternalPath directory") page.Path = "/path/to/foo/bar.html" assert.EqStr("/default/path/to/foo/bar.html", page.GetExternalPath(), "GetExternalPath file") }
func TestParseEntryList(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./entrylist-sample.html") defer file.Close() entryList, err := ParseEntryList(file) assert.Nil(err, "ParseEntryContent should not return an error") assert.EqInt(20, len(entryList), "# of entries") assert.EqStr("http://ameblo.jp/morningmusume-10ki/entry-11874661134.html", entryList[1].Url, "Url") assert.EqStr("早くヴァンプになりた〜い!工藤 遥", entryList[1].Title, "Title") assert.EqInt(126, entryList[1].AmComments, "AmComments") assert.EqInt(551, entryList[1].AmLikes, "AmLikes") }
func TestTwitterClient_GetAppToken_NonJsonResponse(t *testing.T) { assert := wcg.NewAssert(t) httptest.StartMockServer("./dummy", func(ms *httptest.MockServer) { ms.Routes().Post("/oauth2/token", func(res *wcg.Response, req *wcg.Request) { res.WriteString("FOOO") }) client := NewTwitterClient("", "", nil) client.Endpoint = ms.BaseUrl() _, err := client.GetAppToken() assert.NotNil(err, "GetAppToken should return an error when the server returns non JSON response.") }) }
func TestImporter_getCanonicalUrl(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./hellomm.html") defer file.Close() root, _ := html.Parse(file) url := getCanonicalUrl(root) assert.EqStr( "http://www.helloproject.com/event/detail/aa95c6870a1b6ac205c2b6dc3f99cadc4b49085c/", url, "getCanonicalUrl", ) }
func TestHelloProjectImporter_MMTour(t *testing.T) { assert := wcg.NewAssert(t) i := NewHPEventImporter(http.DefaultClient) file, _ := os.Open("./hellomm.html") list, err := i.FromStream(file) file.Close() assert.Nil(err, "ImportFromFile should not return an error") assert.Ok(len(list) > 0, "ImportFromFile should return some entries.") show := list[0] assert.EqStr("ハーモニーホール座間 大ホール", show.VenueName, "VenueName") }
func TestParseRss(t *testing.T) { assert := wcg.NewAssert(t) file, _ := os.Open("./iepg-feed-sample.html") defer file.Close() list, err := ParseRss(file) assert.Nil(err, "ParseRss should not return an error.") assert.EqStr("101072201412050100", list[0], "Id Match") assert.EqStr("101056201412052300", list[1], "Id Match") assert.EqStr("200171201412080100", list[2], "Id Match") assert.EqStr("400639201412081030", list[3], "Id Match") assert.EqStr("101040201412110214", list[4], "Id Match") assert.EqStr("400639201412120930", list[5], "Id Match") }
func TestDatastoreFixture(t *testing.T) { filepath := mkTempfile(`[{ "_kind": "FixtureKind", "_key": "key1", "IntValue": 10, "FloatValue": 2.4, "BoolValue": true, "StringValue": "foobar", "BytesValue": "[]bytesfoobar", "DateTimeValue": "2014-01-02T14:02:50Z", "DateValue": "2014-01-02", "Children": [{ "_kind": "FixtureKindChildren", "_key": "keyc1", "Foo": "bar" }] },{ "_kind": "FixtureKind", "_key": "key1", "_ns": "ns1", "StringValue": "withns1" } ]`) assert := wcg.NewAssert(t) RunTestServer(func(ts *TestServer) { var fk FixtureKind var fkc1 FixtureKindChildren DatastoreFixture(ts.Context, filepath, nil) key := datastore.NewKey(ts.Context, "FixtureKind", "key1", 0, nil) keyc1 := datastore.NewKey(ts.Context, "FixtureKindChildren", "keyc1", 0, key) assert.Nil(datastore.Get(ts.Context, key, &fk), "datastore.Get('key1') ") assert.Nil(datastore.Get(ts.Context, keyc1, &fkc1), "datastore.Get('keyc1') ") assert.EqInt(10, fk.IntValue, "IntValue should be 10") assert.EqFloat32(2.4, fk.FloatValue, "FloatValue should be 2.4") assert.EqStr("foobar", fk.StringValue, "StringValue should be 'foobar'") assert.EqStr("bytesfoobar", string(fk.BytesValue), "BytesValue should be 'foobar'") assert.EqTime(time.Date(2014, 01, 02, 14, 02, 50, 0, time.UTC), fk.DateTimeValue, "DateTimeValue should be 2014-01-02T14:02:50Z") assert.EqTime(time.Date(2014, 01, 02, 0, 0, 0, 0, time.UTC), fk.DateValue, "DateTimeValue should be 2014-01-02T00:00:00Z") // namespace ns1, _ := appengine.Namespace(ts.Context, "ns1") key = datastore.NewKey(ns1, "FixtureKind", "key1", 0, nil) assert.Nil(datastore.Get(ns1, key, &fk), "datastore.Get('key1') /w ns1") assert.EqStr("withns1", fk.StringValue, "StringValue should be 'withns1'") }) }
func TestRecordCache_GetRecords_and_Invalidate(t *testing.T) { test.RunTestServer(func(ts *test.TestServer) { assert := wcg.NewAssert(t) d := NewRecordCacheDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil)) // prepare in_window := genTestRecord() in_window.StartAt = d.today.Add(1 * time.Hour) in_window.EndAt = d.today.Add(2 * time.Hour) d.TvRecord.Save(in_window) future := genTestRecord() future.StartAt = d.today.Add(RECORD_TIME_WINDOW + 1*time.Hour) future.EndAt = future.StartAt.Add(1 * time.Hour) d.TvRecord.Save(future) past := genTestRecord() past.StartAt = d.today.Add(-RECORD_TIME_WINDOW - 1*time.Hour) past.EndAt = past.StartAt.Add(30 * time.Minute) d.TvRecord.Save(past) in_window_iepg := genTestIEpg() in_window.StartAt = d.today.Add(4 * time.Hour) in_window.EndAt = d.today.Add(5 * time.Hour) d.IEpg.Save(in_window_iepg) err := util.WaitFor(func() bool { records, _ := d.TvRecord.NewQuery().Count() iepgs, _ := d.IEpg.NewQuery().Count() return records+iepgs == 4 }, util.DefaultWaitForTimeout) assert.Nil(err, "Confirm TvRecord/IEpg entities has been stored within a timeout window.") list, err := d.GetRecords(false) assert.Nil(err, "RecordCache#GetRecords should not return an error") assert.EqInt(2, len(list), "RecordCache#GetRecords should return 2 records in a time window") // cache check assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "RecordCache#GetRecords should create RecordCacheTypeTvRecord on memcache.") assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "RecordCache#GetRecords should create RecordCacheTypeIEpg on memcache.") // invalidate the keys assert.Ok(!d.Invalidate(future), "RecordCache#Invalidate should not return true if the passed record is out of window (future)") assert.Ok(!d.Invalidate(past), "RecordCache#Invalidate should not return true if the passed record is out of window (future)") assert.Ok(d.Invalidate(in_window), "RecordCache#Invalidate should return true if the passed record is in window") assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "RecordCache#GetRecords should invalidate RecordCacheTypeTvRecord on memcache.") assert.Ok(d.Invalidate(in_window_iepg), "RecordCache#Invalidate should return true if the passed record is in window (iepg)") assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "RecordCache#GetRecords should invalidate RecordCacheTypeIEpg on memcache.") }) }