From a58d59052339d59f2b025d9d4752515c5d439403 Mon Sep 17 00:00:00 2001 From: Haruki TSURUMOTO Date: Sun, 23 Apr 2017 19:17:18 +0900 Subject: [PATCH 1/3] fix client is not set when first use --- cmd/mstdn/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index 4226be3..b7932be 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -329,13 +329,13 @@ func run() int { } client := mastodon.NewClient(config) - if config.AccessToken == "" { - return authenticate(client, config, file) - } app.Metadata = map[string]interface{}{ "client": client, "config": config, } + if config.AccessToken == "" { + return authenticate(client, config, file) + } return nil } From c9a6022f50bbf733cc193cb057d91c64c0b798fb Mon Sep 17 00:00:00 2001 From: Yeechan Lu Date: Sun, 23 Apr 2017 23:54:27 +0800 Subject: [PATCH 2/3] Implement MediaIDs, Visibility, Sensitive and SpoilerText in PostStatus --- status.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/status.go b/status.go index c23c731..11c750b 100644 --- a/status.go +++ b/status.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "time" + "strconv" ) // Status is struct to hold status. @@ -173,8 +174,20 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { if toot.InReplyToID > 0 { params.Set("in_reply_to_id", fmt.Sprint(toot.InReplyToID)) } - // TODO: media_ids, senstitive, spoiler_text, visibility - //params.Set("visibility", "public") + if toot.MediaIDs != nil { + for _, media := range toot.MediaIDs { + params.Add("media_ids[]", strconv.FormatInt(media, 10)) + } + } + if toot.Visibility != "" { + params.Set("visibility", fmt.Sprint(toot.Visibility)) + } + if toot.Sensitive { + params.Set("senstitive", "true") + } + if toot.SpoilerText != "" { + params.Set("spoiler_text", toot.SpoilerText) + } var status Status err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil) From 6f6070b22ecc134392557735923a2a20fb9410c1 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Mon, 24 Apr 2017 01:13:08 +0900 Subject: [PATCH 3/3] Add cmd follow test --- cmd/mstdn/cmd_follow_test.go | 42 +++++++++++++++++++++++++++++++++--- cmd/mstdn/cmd_test.go | 8 +++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/cmd/mstdn/cmd_follow_test.go b/cmd/mstdn/cmd_follow_test.go index ea74526..f4c053b 100644 --- a/cmd/mstdn/cmd_follow_test.go +++ b/cmd/mstdn/cmd_follow_test.go @@ -14,8 +14,17 @@ func TestCmdFollow(t *testing.T) { func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/api/v1/accounts/search": - fmt.Fprintln(w, `[{"id": 123}]`) - return + q := r.URL.Query().Get("q") + if q == "mattn" { + fmt.Fprintln(w, `[{"id": 123}]`) + return + } else if q == "different_id" { + fmt.Fprintln(w, `[{"id": 1234567}]`) + return + } else if q == "empty" { + fmt.Fprintln(w, `[]`) + return + } case "/api/v1/accounts/123/follow": fmt.Fprintln(w, `{"id": 123}`) ok = true @@ -25,7 +34,34 @@ func TestCmdFollow(t *testing.T) { return }, func(app *cli.App) { - app.Run([]string{"mstdn", "follow", "mattn"}) + err := app.Run([]string{"mstdn", "follow", "mattn"}) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + }, + func(app *cli.App) { + err := app.Run([]string{"mstdn", "follow"}) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + }, + func(app *cli.App) { + err := app.Run([]string{"mstdn", "follow", "fail"}) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + }, + func(app *cli.App) { + err := app.Run([]string{"mstdn", "follow", "empty"}) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + }, + func(app *cli.App) { + err := app.Run([]string{"mstdn", "follow", "different_id"}) + if err == nil { + t.Fatalf("should not be fail: %v", err) + } }, ) if !ok { diff --git a/cmd/mstdn/cmd_test.go b/cmd/mstdn/cmd_test.go index eb38282..5bba072 100644 --- a/cmd/mstdn/cmd_test.go +++ b/cmd/mstdn/cmd_test.go @@ -9,7 +9,7 @@ import ( "github.com/urfave/cli" ) -func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string { +func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string { ts := httptest.NewServer(h) defer ts.Close() @@ -31,6 +31,10 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string { Server: "https://example.com", }, } - testFunc(app) + + for _, f := range testFuncs { + f(app) + } + return buf.String() }