From 2b33d0ed4be085a8958ac80868fa9c158df08201 Mon Sep 17 00:00:00 2001 From: Rasmus Lindroth Date: Fri, 30 Dec 2022 12:38:22 +0100 Subject: [PATCH] fix more tests --- streaming_ws_test.go | 26 ++++++++++++++++++++++++++ tags_test.go | 19 ++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/streaming_ws_test.go b/streaming_ws_test.go index e6b6661..a0d8536 100644 --- a/streaming_ws_test.go +++ b/streaming_ws_test.go @@ -59,6 +59,32 @@ func TestStreamingWSHashtag(t *testing.T) { wsTest(t, q, cancel) } +func TestStreamingWSList(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(wsMock)) + defer ts.Close() + + client := NewClient(&Config{Server: ts.URL}).NewWSClient() + ctx, cancel := context.WithCancel(context.Background()) + q, err := client.StreamingWSList(ctx, "123") + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + wsTest(t, q, cancel) +} + +func TestStreamingWSDirect(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(wsMock)) + defer ts.Close() + + client := NewClient(&Config{Server: ts.URL}).NewWSClient() + ctx, cancel := context.WithCancel(context.Background()) + q, err := client.StreamingWSDirect(ctx) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + wsTest(t, q, cancel) +} + func wsMock(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/api/v1/streaming" { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) diff --git a/tags_test.go b/tags_test.go index dc1e9e9..cddd1d8 100644 --- a/tags_test.go +++ b/tags_test.go @@ -137,7 +137,7 @@ func TestTagFollow(t *testing.T) { func TestTagUnfollow(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/tags/test/follow" { + if r.URL.Path != "/api/v1/tags/test/unfollow" { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } @@ -168,11 +168,11 @@ func TestTagUnfollow(t *testing.T) { ClientSecret: "bar", AccessToken: "zoo", }) - _, err := client.TagFollow(context.Background(), "foo") + _, err := client.TagUnfollow(context.Background(), "foo") if err == nil { t.Fatalf("should be fail: %v", err) } - tag, err := client.TagFollow(context.Background(), "test") + tag, err := client.TagUnfollow(context.Background(), "test") if err != nil { t.Fatalf("should not be fail: %v", err) } @@ -201,6 +201,15 @@ func TestTagUnfollow(t *testing.T) { func TestTagsFollowed(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/followed_tags" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } + if r.FormValue("limit") == "1" { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + fmt.Fprintln(w, ` [{ "name": "test", @@ -245,6 +254,10 @@ func TestTagsFollowed(t *testing.T) { ClientSecret: "bar", AccessToken: "zoo", }) + _, err := client.TagsFollowed(context.Background(), &Pagination{Limit: 1}) + if err == nil { + t.Fatalf("should be fail: %v", err) + } tags, err := client.TagsFollowed(context.Background(), nil) if err != nil { t.Fatalf("should not be fail: %v", err)