From d0504fea0f59e1cc4eec5da67ded9c47d88cc19f Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Wed, 3 May 2017 03:05:36 +0900 Subject: [PATCH] Add TestCmdXSearch and TestCmdMikami --- cmd/mstdn/cmd_mikami_test.go | 41 +++++++++++++++++++++++++++++++++++ cmd/mstdn/cmd_test.go | 1 + cmd/mstdn/cmd_xsearch_test.go | 16 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 cmd/mstdn/cmd_mikami_test.go diff --git a/cmd/mstdn/cmd_mikami_test.go b/cmd/mstdn/cmd_mikami_test.go new file mode 100644 index 0000000..3fe9eae --- /dev/null +++ b/cmd/mstdn/cmd_mikami_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "bytes" + "fmt" + "net/http" + "strings" + "testing" + + "github.com/urfave/cli" +) + +func TestCmdMikami(t *testing.T) { + ok := false + buf := bytes.NewBuffer(nil) + testWithServer( + func(w http.ResponseWriter, r *http.Request) { + if r.URL.Query().Get("q") == "三上" { + ok = true + fmt.Fprintln(w, `

三上

`) + } + }, + func(app *cli.App) { + app.Writer = buf + err := app.Run([]string{"mstdn", "mikami"}) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + }, + ) + if !ok { + t.Fatal("should be search Mikami") + } + result := buf.String() + if !strings.Contains(result, "http://example.com/@test/1") { + t.Fatalf("%q should be contained in output of search: %s", "http://example.com/@test/1", result) + } + if !strings.Contains(result, "三上") { + t.Fatalf("%q should be contained in output of search: %s", "三上", result) + } +} diff --git a/cmd/mstdn/cmd_test.go b/cmd/mstdn/cmd_test.go index 5bba072..14043c3 100644 --- a/cmd/mstdn/cmd_test.go +++ b/cmd/mstdn/cmd_test.go @@ -30,6 +30,7 @@ func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string { "config": &mastodon.Config{ Server: "https://example.com", }, + "xsearch_url": ts.URL, } for _, f := range testFuncs { diff --git a/cmd/mstdn/cmd_xsearch_test.go b/cmd/mstdn/cmd_xsearch_test.go index 1c91aca..f3dc105 100644 --- a/cmd/mstdn/cmd_xsearch_test.go +++ b/cmd/mstdn/cmd_xsearch_test.go @@ -7,8 +7,24 @@ import ( "net/http/httptest" "strings" "testing" + + "github.com/urfave/cli" ) +func TestCmdXSearch(t *testing.T) { + testWithServer( + func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `

test status

`) + }, + func(app *cli.App) { + err := app.Run([]string{"mstdn", "xsearch", "test"}) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + }, + ) +} + func TestXSearch(t *testing.T) { canErr := true ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {