Skip to content

Commit

Permalink
test: added missing testCase trend
Browse files Browse the repository at this point in the history
  • Loading branch information
kyokomi committed Jan 14, 2015
1 parent ddb509e commit b296b8b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 19 deletions.
11 changes: 5 additions & 6 deletions docomo/dialogue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package docomo

import (
"testing"
"reflect"
)

func TestDialogueGet(t *testing.T) {

type TestCase struct {
in string
out string
out DialogueResponse
}

testCase := TestCase{
in: "../tests/stubs/dialogue.json",
out: "こんにちは。ちょうど退屈してたんだ。",
}

serve, client := Stub(testCase.in)
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

d := DialogueRequest{}
Expand All @@ -25,7 +24,7 @@ func TestDialogueGet(t *testing.T) {
t.Errorf("error Request %s\n", err)
}

if res.Utt != testCase.out {
t.Errorf("error Response %s != \n", res.Utt, testCase.out)
if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}
19 changes: 8 additions & 11 deletions docomo/knowledge_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package docomo

import "testing"
import (
"testing"
"reflect"
)

func TestKnowledgeGet(t *testing.T) {

type TestCase struct {
in string
out string
out KnowledgeQAResponse
}

testCase := TestCase{
in: "../tests/stubs/knowledge.json",
out: "ガガーリン",
}

serve, client := Stub(testCase.in)
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

req := KnowledgeQARequest{}
Expand All @@ -23,12 +25,7 @@ func TestKnowledgeGet(t *testing.T) {
t.Errorf("error Request %s\n", err)
}

answers := 5
if len(res.Answers) != answers {
t.Errorf("error Response answers lenght %d != %d\n", len(res.Answers), answers)
}

if res.Answers[0].AnswerText != testCase.out {
t.Errorf("error Response %s != %s\n", res.Answers[0].AnswerText, testCase.out)
if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}
13 changes: 12 additions & 1 deletion docomo/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"log"
"net/http"
"net/http/httptest"
"encoding/json"
)

// Stub test用のスタブ
func Stub(filename string) (*httptest.Server, *Client) {
func Stub(filename string, outRes interface{}) (*httptest.Server, *Client) {
stub, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalln(err)
Expand All @@ -18,5 +19,15 @@ func Stub(filename string) (*httptest.Server, *Client) {
}))
c := NewClient("")
c.SetDomain(ts.URL)

// testCase out data
data, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalln(err)
}
if err := json.Unmarshal(data, outRes); err != nil {
log.Fatalln(err)
}

return ts, c
}
104 changes: 104 additions & 0 deletions docomo/trend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package docomo

import (
"testing"
"reflect"
)

func TestTrendGetGenre(t *testing.T) {
type TestCase struct {
in string
out TrendGenreResponse
}

testCase := TestCase{
in: "../tests/stubs/trend_genre.json",
}
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

req := TrendGenreRequest{}
res, err := client.Trend.GetGenre(req)
if err != nil {
t.Errorf("error Request %s\n", err)
}

if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}

func TestTrendGetContents(t *testing.T) {
type TestCase struct {
in string
out TrendContentsResponse
}

testCase := TestCase{
in: "../tests/stubs/trend_contents.json",
}
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

req := TrendContentsRequest{}
var genreID int = 1
req.GenreID = &genreID
res, err := client.Trend.GetContents(req)
if err != nil {
t.Errorf("error Request %s\n", err)
}

if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}

func TestTrendGetSearch(t *testing.T) {
type TestCase struct {
in string
out TrendSearchResponse
}

testCase := TestCase{
in: "../tests/stubs/trend_search.json",
}
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

req := TrendSearchRequest{}
var keyword string = "test"
req.Keyword = &keyword
res, err := client.Trend.GetSearch(req)
if err != nil {
t.Errorf("error Request %s\n", err)
}

if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}

func TestTrendGetRelated(t *testing.T) {
type TestCase struct {
in string
out TrendRelatedResponse
}

testCase := TestCase{
in: "../tests/stubs/trend_related.json",
}
serve, client := Stub(testCase.in, &testCase.out)
defer serve.Close()

req := TrendRelatedRequest{}
var contentID int = 1
req.ContentID = &contentID
res, err := client.Trend.GetRelated(req)
if err != nil {
t.Errorf("error Request %s\n", err)
}

if !reflect.DeepEqual(*res, testCase.out) {
t.Errorf("error Response %s != %s\n", res, testCase.out)
}
}
2 changes: 1 addition & 1 deletion tests/stubs/trend_search.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"totalResults":7,"startIndex":1,"itemsPerPage":7,"issueDate":"2015-01-10T16:05:19+0900","articleContents":[{"contentId":332209,"contentType":10,"genreId":5,"contentData":{"title":"【イベントレポート】Qualcomm、450MbpsのLTEや7GbpsのWiGigをデモ 〜Quick Charge 2.0対応機器も拡大中 ","body":"Qualcommは、International CESで同社のソリューションを多数展示した。基調講演に関しては別記事でお伝えした通り、昨年(2014年)発表済みのSnapdragon 810が実際の…","imageUrl":"http://pc.watch.impress.co.jp/img/pcw/docs/683/318/01.jpg","imageSize":{"height":531,"width":800},"createdDate":"2015-01-10T11:24:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/event/20150110_683318.html"}},{"contentId":330011,"contentType":10,"genreId":5,"contentData":{"title":"ついにボタン型コンピュータ「Curie」が登場——2015年のIntelは何を目指すのか (1/3)","body":"ウェアラブルや3DインタフェースにかけるIntelの情熱は本物かもしれない——というのが2015年を迎えての最初の感想だ。  米Intelのブライアン・クルザニッチCEOは1月6日(米国時間)、米ネ…","createdDate":"2015-01-08T18:30:00+0900","sourceDomain":"www.itmedia.co.jp","sourceName":"ITmedia","linkUrl":"http://www.itmedia.co.jp/pcuser/articles/1501/08/news137.html"}},{"contentId":330483,"contentType":10,"genreId":1,"contentData":{"title":"ホンダに過去最高の7000万ドル制裁金、事故報告漏れ-米当局","body":"(ブルームバーグ):ホンダ は車両の不具合の可能性に関連した保証請求や1700件超の死傷事故で米当局への報告漏れがあったとして7000万ドル(約84億円)の制裁金支払いに合意し、監督強化にも同意した…","imageUrl":"http://www.bloomberg.co.jp/apps/data?pid=avimage&iid=iIPJYdITJiIM","imageSize":{"height":427,"width":640},"createdDate":"2015-01-09T04:04:00+0900","sourceDomain":"www.bloomberg.co.jp","sourceName":"ブルームバーグ","linkUrl":"http://www.bloomberg.co.jp/news/123-NHVDZT6VDKHV01.html"}},{"contentId":331074,"contentType":10,"genreId":5,"contentData":{"title":"BCN、恒例の年間販売数ランキング「BCN AWARD 2015」を発表 ","body":"株式会社BCNは9日、全国のPOSデータを元にした2014年の販売数ランキング「BCN AWARD 2015」を発表した。  今年はハードウェア85部門、ソフトウェア33部門の計118部門でランキン…","createdDate":"2015-01-09T14:23:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/20150109_683181.html"}},{"contentId":328639,"contentType":10,"genreId":13,"contentData":{"title":"Razer,SensicsなどがVRのオープンソースプラットフォームを提言。VR HMD「OSVR Hacker Dev Kit」も199.99ドルで発売予定","body":"2015年1月6日,Razerと関連企業は,現在,米ラスベガスで開催されている「2015 CES」にて仮想現実(Virtual Realiry,以下VR)対応ゲームのためのオープンソースプラットフォ…","imageUrl":"http://www.4gamer.net/games/999/G999902/20150107082/TN/001.jpg","imageSize":{"height":193,"width":254},"createdDate":"2015-01-07T21:49:00+0900","sourceDomain":"www.4gamer.net","sourceName":"4Gamer.net","linkUrl":"http://www.4gamer.net/games/999/G999902/20150107082/"}},{"contentId":328512,"contentType":10,"genreId":13,"contentData":{"title":"Gamer Razer、VR技術のプログラミングを可能にするオープンソースソフトウェア&デバイス「OSVR Hacker Dev Kit」を発表","body":"Razerは、バーチャルリアリティのプログラミングに関するオープンソースソフトウェアおよびデバイスである、「オープンソース・バーチャルリアリティ・エコシステム(OSVR)」を発表した。","imageUrl":"http://image.gamer.ne.jp/news/2015/20150107/00468f9c7d4d45a41e166c0c052a3d2856c1/m/1.jpg","imageSize":{"height":215,"width":298},"createdDate":"2015-01-07T19:05:00+0900","sourceDomain":"www.gamer.ne.jp","sourceName":"Gamer","linkUrl":"http://www.gamer.ne.jp/news/201501070046/"}},{"contentId":326305,"contentType":10,"genreId":5,"contentData":{"title":"【イベントレポート】NVIDIAが発表したTegra X1ってどんなSoC? ","body":"別記事でも紹介しているように、NVIDIAは開発コードネームErista(アリスタ)で知られる、次世代Tegraを「Tegra X1」として発表し、今年の前半に出荷開始する予定であることを明らかにし…","imageUrl":"http://pc.watch.impress.co.jp/img/pcw/docs/682/499/01.jpg","imageSize":{"height":496,"width":800},"createdDate":"2015-01-06T06:00:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/event/20150106_682499.html"}}]}cat
{"totalResults":7,"startIndex":1,"itemsPerPage":7,"issueDate":"2015-01-10T16:05:19+0900","articleContents":[{"contentId":332209,"contentType":10,"genreId":5,"contentData":{"title":"【イベントレポート】Qualcomm、450MbpsのLTEや7GbpsのWiGigをデモ 〜Quick Charge 2.0対応機器も拡大中 ","body":"Qualcommは、International CESで同社のソリューションを多数展示した。基調講演に関しては別記事でお伝えした通り、昨年(2014年)発表済みのSnapdragon 810が実際の…","imageUrl":"http://pc.watch.impress.co.jp/img/pcw/docs/683/318/01.jpg","imageSize":{"height":531,"width":800},"createdDate":"2015-01-10T11:24:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/event/20150110_683318.html"}},{"contentId":330011,"contentType":10,"genreId":5,"contentData":{"title":"ついにボタン型コンピュータ「Curie」が登場——2015年のIntelは何を目指すのか (1/3)","body":"ウェアラブルや3DインタフェースにかけるIntelの情熱は本物かもしれない——というのが2015年を迎えての最初の感想だ。  米Intelのブライアン・クルザニッチCEOは1月6日(米国時間)、米ネ…","createdDate":"2015-01-08T18:30:00+0900","sourceDomain":"www.itmedia.co.jp","sourceName":"ITmedia","linkUrl":"http://www.itmedia.co.jp/pcuser/articles/1501/08/news137.html"}},{"contentId":330483,"contentType":10,"genreId":1,"contentData":{"title":"ホンダに過去最高の7000万ドル制裁金、事故報告漏れ-米当局","body":"(ブルームバーグ):ホンダ は車両の不具合の可能性に関連した保証請求や1700件超の死傷事故で米当局への報告漏れがあったとして7000万ドル(約84億円)の制裁金支払いに合意し、監督強化にも同意した…","imageUrl":"http://www.bloomberg.co.jp/apps/data?pid=avimage&iid=iIPJYdITJiIM","imageSize":{"height":427,"width":640},"createdDate":"2015-01-09T04:04:00+0900","sourceDomain":"www.bloomberg.co.jp","sourceName":"ブルームバーグ","linkUrl":"http://www.bloomberg.co.jp/news/123-NHVDZT6VDKHV01.html"}},{"contentId":331074,"contentType":10,"genreId":5,"contentData":{"title":"BCN、恒例の年間販売数ランキング「BCN AWARD 2015」を発表 ","body":"株式会社BCNは9日、全国のPOSデータを元にした2014年の販売数ランキング「BCN AWARD 2015」を発表した。  今年はハードウェア85部門、ソフトウェア33部門の計118部門でランキン…","createdDate":"2015-01-09T14:23:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/20150109_683181.html"}},{"contentId":328639,"contentType":10,"genreId":13,"contentData":{"title":"Razer,SensicsなどがVRのオープンソースプラットフォームを提言。VR HMD「OSVR Hacker Dev Kit」も199.99ドルで発売予定","body":"2015年1月6日,Razerと関連企業は,現在,米ラスベガスで開催されている「2015 CES」にて仮想現実(Virtual Realiry,以下VR)対応ゲームのためのオープンソースプラットフォ…","imageUrl":"http://www.4gamer.net/games/999/G999902/20150107082/TN/001.jpg","imageSize":{"height":193,"width":254},"createdDate":"2015-01-07T21:49:00+0900","sourceDomain":"www.4gamer.net","sourceName":"4Gamer.net","linkUrl":"http://www.4gamer.net/games/999/G999902/20150107082/"}},{"contentId":328512,"contentType":10,"genreId":13,"contentData":{"title":"Gamer Razer、VR技術のプログラミングを可能にするオープンソースソフトウェア&デバイス「OSVR Hacker Dev Kit」を発表","body":"Razerは、バーチャルリアリティのプログラミングに関するオープンソースソフトウェアおよびデバイスである、「オープンソース・バーチャルリアリティ・エコシステム(OSVR)」を発表した。","imageUrl":"http://image.gamer.ne.jp/news/2015/20150107/00468f9c7d4d45a41e166c0c052a3d2856c1/m/1.jpg","imageSize":{"height":215,"width":298},"createdDate":"2015-01-07T19:05:00+0900","sourceDomain":"www.gamer.ne.jp","sourceName":"Gamer","linkUrl":"http://www.gamer.ne.jp/news/201501070046/"}},{"contentId":326305,"contentType":10,"genreId":5,"contentData":{"title":"【イベントレポート】NVIDIAが発表したTegra X1ってどんなSoC? ","body":"別記事でも紹介しているように、NVIDIAは開発コードネームErista(アリスタ)で知られる、次世代Tegraを「Tegra X1」として発表し、今年の前半に出荷開始する予定であることを明らかにし…","imageUrl":"http://pc.watch.impress.co.jp/img/pcw/docs/682/499/01.jpg","imageSize":{"height":496,"width":800},"createdDate":"2015-01-06T06:00:00+0900","sourceDomain":"pc.watch.impress.co.jp","sourceName":"PC Watch","linkUrl":"http://pc.watch.impress.co.jp/docs/news/event/20150106_682499.html"}}]}

0 comments on commit b296b8b

Please sign in to comment.