diff --git a/account_test.go b/account_test.go index 28b5d02..5804b5a 100644 --- a/account_test.go +++ b/account_test.go @@ -126,7 +126,8 @@ func TestAccountService_Info(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/info.json") + blob, err := readFileContents("testdata/account/info.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -142,7 +143,8 @@ func TestAccountService_Karma(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/karma.json") + blob, err := readFileContents("testdata/account/karma.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me/karma", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -158,7 +160,8 @@ func TestAccountService_Settings(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/settings.json") + blob, err := readFileContents("testdata/account/settings.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me/prefs", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -174,7 +177,9 @@ func TestAccountService_UpdateSettings(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/settings.json") + blob, err := readFileContents("testdata/account/settings.json") + assert.NoError(t, err) + expectedSettingsBody := &Settings{NumberOfPosts: Int(10), MinimumCommentScore: Int(5), Compress: Bool(true)} mux.HandleFunc("/api/v1/me/prefs", func(w http.ResponseWriter, r *http.Request) { @@ -197,7 +202,8 @@ func TestAccountService_Trophies(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/trophies.json") + blob, err := readFileContents("testdata/account/trophies.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me/trophies", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -213,7 +219,8 @@ func TestAccountService_Friends(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/friends.json") + blob, err := readFileContents("testdata/account/friends.json") + assert.NoError(t, err) mux.HandleFunc("/prefs/friends", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -229,7 +236,8 @@ func TestAccountService_Blocked(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/blocked.json") + blob, err := readFileContents("testdata/account/blocked.json") + assert.NoError(t, err) mux.HandleFunc("/prefs/blocked", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -245,7 +253,8 @@ func TestAccountService_Messaging(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/messaging.json") + blob, err := readFileContents("testdata/account/messaging.json") + assert.NoError(t, err) mux.HandleFunc("/prefs/messaging", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -262,7 +271,8 @@ func TestAccountService_Trusted(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/account/trusted.json") + blob, err := readFileContents("testdata/account/trusted.json") + assert.NoError(t, err) mux.HandleFunc("/prefs/trusted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) diff --git a/comment_test.go b/comment_test.go index 70393fd..a72e4f1 100644 --- a/comment_test.go +++ b/comment_test.go @@ -42,7 +42,8 @@ func TestCommentService_Submit(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/comment-submit-edit.json") + blob, err := readFileContents("testdata/comment-submit-edit.json") + assert.NoError(t, err) mux.HandleFunc("/api/comment", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method) @@ -69,7 +70,8 @@ func TestCommentService_Edit(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/comment-submit-edit.json") + blob, err := readFileContents("testdata/comment-submit-edit.json") + assert.NoError(t, err) mux.HandleFunc("/api/editusertext", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method) diff --git a/flair_test.go b/flair_test.go index 74aa1bb..207950d 100644 --- a/flair_test.go +++ b/flair_test.go @@ -44,7 +44,8 @@ func TestFlairService_GetFlairs(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/flairs.json") + blob, err := readFileContents("testdata/flairs.json") + assert.NoError(t, err) mux.HandleFunc("/r/subreddit/api/user_flair", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -60,7 +61,8 @@ func TestFlairService_GetFlairsV2(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/flairs-v2.json") + blob, err := readFileContents("testdata/flairs-v2.json") + assert.NoError(t, err) mux.HandleFunc("/r/subreddit/api/user_flair_v2", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) diff --git a/moderation_test.go b/moderation_test.go index 9b364c2..4361583 100644 --- a/moderation_test.go +++ b/moderation_test.go @@ -53,7 +53,8 @@ func TestModerationService_GetActions(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/moderation/actions.json") + blob, err := readFileContents("testdata/moderation/actions.json") + assert.NoError(t, err) mux.HandleFunc("/r/testsubreddit/about/log", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -69,7 +70,8 @@ func TestModerationService_GetActionsByType(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/moderation/actions.json") + blob, err := readFileContents("testdata/moderation/actions.json") + assert.NoError(t, err) mux.HandleFunc("/r/testsubreddit/about/log", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -93,7 +95,8 @@ func TestModerationService_AcceptInvite(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/moderation/actions.json") + blob, err := readFileContents("testdata/moderation/actions.json") + assert.NoError(t, err) mux.HandleFunc("/r/testsubreddit/api/accept_moderator_invite", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method) @@ -108,7 +111,7 @@ func TestModerationService_AcceptInvite(t *testing.T) { fmt.Fprint(w, blob) }) - _, err := client.Moderation.AcceptInvite(ctx, "testsubreddit") + _, err = client.Moderation.AcceptInvite(ctx, "testsubreddit") assert.NoError(t, err) } diff --git a/multi_test.go b/multi_test.go index 672f983..86c6c1d 100644 --- a/multi_test.go +++ b/multi_test.go @@ -47,7 +47,8 @@ func TestMultiService_Get(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multi.json") + blob, err := readFileContents("testdata/multi/multi.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/user/testuser/m/testmulti", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -63,7 +64,8 @@ func TestMultiService_Mine(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multis.json") + blob, err := readFileContents("testdata/multi/multis.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/mine", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -79,7 +81,8 @@ func TestMultiService_Of(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multis.json") + blob, err := readFileContents("testdata/multi/multis.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/user/test", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -95,7 +98,8 @@ func TestMultiService_Copy(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multi.json") + blob, err := readFileContents("testdata/multi/multi.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/copy", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method) @@ -127,7 +131,9 @@ func TestMultiService_Create(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multi.json") + blob, err := readFileContents("testdata/multi/multi.json") + assert.NoError(t, err) + createRequest := &MultiCreateOrUpdateRequest{ Name: "testmulti", Description: "this is a multireddit", @@ -160,7 +166,9 @@ func TestMultiService_Update(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/multi.json") + blob, err := readFileContents("testdata/multi/multi.json") + assert.NoError(t, err) + updateRequest := &MultiCreateOrUpdateRequest{ Name: "testmulti", Description: "this is a multireddit", @@ -204,7 +212,8 @@ func TestMultiService_GetDescription(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/description.json") + blob, err := readFileContents("testdata/multi/description.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/user/testuser/m/testmulti/description", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -220,7 +229,8 @@ func TestMultiService_UpdateDescription(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/multi/description.json") + blob, err := readFileContents("testdata/multi/description.json") + assert.NoError(t, err) mux.HandleFunc("/api/multi/user/testuser/m/testmulti/description", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method) diff --git a/post_test.go b/post_test.go index 2bc2f93..0620d8c 100644 --- a/post_test.go +++ b/post_test.go @@ -98,7 +98,8 @@ func TestPostService_Get(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/post/post.json") + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) mux.HandleFunc("/comments/test", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -585,7 +586,8 @@ func TestPostService_More(t *testing.T) { }, } - blob := readFileContents(t, "testdata/post/more.json") + blob, err := readFileContents("testdata/post/more.json") + assert.NoError(t, err) mux.HandleFunc("/api/morechildren", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -602,7 +604,7 @@ func TestPostService_More(t *testing.T) { fmt.Fprint(w, blob) }) - _, err := client.Post.More(ctx, parentComment) + _, err = client.Post.More(ctx, parentComment) assert.NoError(t, err) assert.Nil(t, parentComment.Replies.MoreComments) assert.Len(t, parentComment.Replies.Comments, 1) @@ -641,7 +643,8 @@ func TestPostService_RandomFromSubreddits(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/post/post.json") + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) mux.HandleFunc("/r/test/random", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -658,7 +661,8 @@ func TestPostService_Random(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/post/post.json") + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) mux.HandleFunc("/r/all/random", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -675,7 +679,8 @@ func TestPostService_RandomFromSubscriptions(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/post/post.json") + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) mux.HandleFunc("/random", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) diff --git a/reddit_test.go b/reddit_test.go index 4ab5036..87fd59d 100644 --- a/reddit_test.go +++ b/reddit_test.go @@ -49,19 +49,19 @@ func teardown() { server.Close() } -func readFileContents(t *testing.T, filepath string) string { - file, err := os.Open(filepath) +func readFileContents(path string) (string, error) { + file, err := os.Open(path) if err != nil { - t.Fatalf("got unexpected error: %v", err) + return "", err } defer file.Close() bytes, err := ioutil.ReadAll(file) if err != nil { - t.Fatalf("got unexpected error: %v", err) + return "", err } - return string(bytes) + return string(bytes), err } func testClientServices(t *testing.T, c *Client) { diff --git a/subreddit_test.go b/subreddit_test.go index c5898a8..ab20712 100644 --- a/subreddit_test.go +++ b/subreddit_test.go @@ -136,7 +136,8 @@ func TestSubredditService_GetByName(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/about.json") + blob, err := readFileContents("testdata/subreddit/about.json") + assert.NoError(t, err) mux.HandleFunc("/r/golang/about", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -152,7 +153,8 @@ func TestSubredditService_GetPopular(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/popular", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -168,7 +170,8 @@ func TestSubredditService_GetNew(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/new", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -184,7 +187,8 @@ func TestSubredditService_GetGold(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/gold", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -200,7 +204,8 @@ func TestSubredditService_GetDefault(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/default", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -216,7 +221,8 @@ func TestSubredditService_GetSubscribed(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/mine/subscriber", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -232,7 +238,8 @@ func TestSubredditService_GetApproved(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/mine/contributor", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -248,7 +255,8 @@ func TestSubredditService_GetModerated(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/list.json") + blob, err := readFileContents("testdata/subreddit/list.json") + assert.NoError(t, err) mux.HandleFunc("/subreddits/mine/moderator", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -265,7 +273,8 @@ func TestSubredditService_GetModerated(t *testing.T) { // setup() // defer teardown() -// blob := readFileContents(t, "testdata/subreddit/sticky.json") +// blob, err:= readFileContents( "testdata/subreddit/sticky.json") +// assert.NoError(t,err) // mux.HandleFunc("/r/nba/about/sticky", func(w http.ResponseWriter, r *http.Request) { // assert.Equal(t, http.MethodGet, r.Method) @@ -288,7 +297,8 @@ func TestSubredditService_Moderators(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/moderators.json") + blob, err := readFileContents("testdata/subreddit/moderators.json") + assert.NoError(t, err) mux.HandleFunc("/r/test/about/moderators", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -304,7 +314,8 @@ func TestSubredditService_Random(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/random.json") + blob, err := readFileContents("testdata/subreddit/random.json") + assert.NoError(t, err) mux.HandleFunc("/r/random", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -326,7 +337,8 @@ func TestSubredditService_RandomNSFW(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/subreddit/random.json") + blob, err := readFileContents("testdata/subreddit/random.json") + assert.NoError(t, err) mux.HandleFunc("/r/randnsfw", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) diff --git a/user_test.go b/user_test.go index b879cc1..e8c831d 100644 --- a/user_test.go +++ b/user_test.go @@ -133,7 +133,8 @@ func TestUserService_Get(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/get.json") + blob, err := readFileContents("testdata/user/get.json") + assert.NoError(t, err) mux.HandleFunc("/user/Test_User/about", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -149,7 +150,8 @@ func TestUserService_GetMultipleByID(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/get-multiple-by-id.json") + blob, err := readFileContents("testdata/user/get-multiple-by-id.json") + assert.NoError(t, err) mux.HandleFunc("/api/user_data_by_account_ids", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -196,7 +198,8 @@ func TestUserService_Overview(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/overview.json") + blob, err := readFileContents("testdata/user/overview.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/overview", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -221,7 +224,8 @@ func TestUserService_OverviewOf(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/overview.json") + blob, err := readFileContents("testdata/user/overview.json") + assert.NoError(t, err) mux.HandleFunc("/user/user2/overview", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -246,7 +250,8 @@ func TestUserService_Overview_Options(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/overview.json") + blob, err := readFileContents("testdata/user/overview.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/overview", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -263,7 +268,7 @@ func TestUserService_Overview_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, _, err := client.User.Overview(ctx, SetLimit(5), SetAfter("t3_after"), SetSort(SortTop)) + _, _, _, err = client.User.Overview(ctx, SetLimit(5), SetAfter("t3_after"), SetSort(SortTop)) assert.NoError(t, err) } @@ -271,7 +276,8 @@ func TestUserService_Posts(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/submitted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -291,7 +297,8 @@ func TestUserService_PostsOf(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user2/submitted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -311,7 +318,8 @@ func TestUserService_Posts_Options(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/submitted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -327,7 +335,7 @@ func TestUserService_Posts_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, err := client.User.Posts(ctx, SetLimit(10), SetSort(SortNew)) + _, _, err = client.User.Posts(ctx, SetLimit(10), SetSort(SortNew)) assert.NoError(t, err) } @@ -335,7 +343,8 @@ func TestUserService_Comments(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/comments.json") + blob, err := readFileContents("testdata/user/comments.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/comments", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -355,7 +364,8 @@ func TestUserService_CommentsOf(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/comments.json") + blob, err := readFileContents("testdata/user/comments.json") + assert.NoError(t, err) mux.HandleFunc("/user/user2/comments", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -375,7 +385,8 @@ func TestUserService_Comments_Options(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/comments.json") + blob, err := readFileContents("testdata/user/comments.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/comments", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -391,7 +402,7 @@ func TestUserService_Comments_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, err := client.User.Comments(ctx, SetLimit(100), SetBefore("t1_before")) + _, _, err = client.User.Comments(ctx, SetLimit(100), SetBefore("t1_before")) assert.NoError(t, err) } @@ -400,7 +411,8 @@ func TestUserService_Saved(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/overview.json") + blob, err := readFileContents("testdata/user/overview.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/saved", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -426,7 +438,8 @@ func TestUserService_Saved_Options(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/overview.json") + blob, err := readFileContents("testdata/user/overview.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/saved", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -442,7 +455,7 @@ func TestUserService_Saved_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, _, err := client.User.Saved(ctx, SetLimit(50), SetSort(SortControversial)) + _, _, _, err = client.User.Saved(ctx, SetLimit(50), SetSort(SortControversial)) assert.NoError(t, err) } func TestUserService_Upvoted(t *testing.T) { @@ -450,7 +463,8 @@ func TestUserService_Upvoted(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/upvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -471,7 +485,8 @@ func TestUserService_Upvoted_Options(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/upvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -487,7 +502,7 @@ func TestUserService_Upvoted_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, err := client.User.Upvoted(ctx, SetLimit(30), SetAfter("t3_after")) + _, _, err = client.User.Upvoted(ctx, SetLimit(30), SetAfter("t3_after")) assert.NoError(t, err) } @@ -496,7 +511,8 @@ func TestUserService_UpvotedOf(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user2/upvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -517,7 +533,8 @@ func TestUserService_Downvoted(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/downvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -538,7 +555,8 @@ func TestUserService_Downvoted_Options(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/downvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -554,7 +572,7 @@ func TestUserService_Downvoted_Options(t *testing.T) { fmt.Fprint(w, blob) }) - _, _, err := client.User.Downvoted(ctx, SetLimit(20), SetBefore("t3_before")) + _, _, err = client.User.Downvoted(ctx, SetLimit(20), SetBefore("t3_before")) assert.NoError(t, err) } @@ -563,7 +581,8 @@ func TestUserService_DownvotedOf(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user2/downvoted", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -584,7 +603,8 @@ func TestUserService_Hidden(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/hidden", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -605,7 +625,8 @@ func TestUserService_Gilded(t *testing.T) { defer teardown() // we'll use this, similar payloads - blob := readFileContents(t, "testdata/user/submitted.json") + blob, err := readFileContents("testdata/user/submitted.json") + assert.NoError(t, err) mux.HandleFunc("/user/user1/gilded", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -625,7 +646,8 @@ func TestUserService_GetFriendship(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/friend.json") + blob, err := readFileContents("testdata/user/friend.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me/friends/test123", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -641,7 +663,8 @@ func TestUserService_Friend(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/friend.json") + blob, err := readFileContents("testdata/user/friend.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/me/friends/test123", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method) @@ -681,7 +704,8 @@ func TestUserService_Block(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/block.json") + blob, err := readFileContents("testdata/user/block.json") + assert.NoError(t, err) mux.HandleFunc("/api/block_user", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method) @@ -705,7 +729,8 @@ func TestUserService_Block(t *testing.T) { // setup() // defer teardown() -// blob := readFileContents(t, "testdata/user/block.json") +// blob, err := readFileContents("testdata/user/block.json") +// assert.NoError(t,err) // mux.HandleFunc("/api/block_user", func(w http.ResponseWriter, r *http.Request) { // assert.Equal(t, http.MethodPost, r.Method) @@ -775,7 +800,8 @@ func TestUserService_Trophies(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/trophies.json") + blob, err := readFileContents("testdata/user/trophies.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/user/user1/trophies", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) @@ -791,7 +817,8 @@ func TestUserService_TrophiesOf(t *testing.T) { setup() defer teardown() - blob := readFileContents(t, "testdata/user/trophies.json") + blob, err := readFileContents("testdata/user/trophies.json") + assert.NoError(t, err) mux.HandleFunc("/api/v1/user/test123/trophies", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method)