go-mastodon/cmd/mstdn/cmd_toot_test.go

53 lines
1.0 KiB
Go
Raw Normal View History

2017-04-16 15:37:46 +02:00
package main
import (
"fmt"
"net/http"
"testing"
2022-11-27 05:24:42 +01:00
"github.com/urfave/cli/v2"
2017-04-16 15:37:46 +02:00
)
func TestCmdToot(t *testing.T) {
toot := ""
testWithServer(
func(w http.ResponseWriter, r *http.Request) {
2017-04-16 16:49:04 +02:00
switch r.URL.Path {
case "/api/v1/statuses":
toot = r.FormValue("status")
2017-04-20 15:41:49 +02:00
fmt.Fprintln(w, `{"id": 2345}`)
2017-04-16 15:37:46 +02:00
return
}
2017-04-16 16:49:04 +02:00
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
2017-04-16 15:37:46 +02:00
return
},
func(app *cli.App) {
app.Run([]string{"mstdn", "toot", "foo"})
},
)
if toot != "foo" {
t.Fatalf("want %q, got %q", "foo", toot)
}
}
2017-04-24 12:47:07 +02:00
func TestCmdTootFileNotFound(t *testing.T) {
var err error
testWithServer(
func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/statuses":
fmt.Fprintln(w, `{"id": 2345}`)
return
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
},
func(app *cli.App) {
err = app.Run([]string{"mstdn", "toot", "-ff", "not-found"})
},
)
if err == nil {
t.Fatal("should be fail")
}
}