Add TestCmdXSearch and TestCmdMikami

This commit is contained in:
178inaba 2017-05-03 03:05:36 +09:00
parent a796ca03c5
commit d0504fea0f
3 changed files with 58 additions and 0 deletions

View File

@ -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, `<div class="post"><div class="mst_content"><a href="http://example.com/@test/1"><p>三上</p></a></div></div>`)
}
},
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)
}
}

View File

@ -30,6 +30,7 @@ func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string {
"config": &mastodon.Config{ "config": &mastodon.Config{
Server: "https://example.com", Server: "https://example.com",
}, },
"xsearch_url": ts.URL,
} }
for _, f := range testFuncs { for _, f := range testFuncs {

View File

@ -7,8 +7,24 @@ import (
"net/http/httptest" "net/http/httptest"
"strings" "strings"
"testing" "testing"
"github.com/urfave/cli"
) )
func TestCmdXSearch(t *testing.T) {
testWithServer(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `<div class="post"><div class="mst_content"><a href="http://example.com/@test/1"><p>test status</p></a></div></div>`)
},
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) { func TestXSearch(t *testing.T) {
canErr := true canErr := true
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {