Fix tests

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-07-30 12:22:39 -04:00
parent 112f7f0370
commit d65358b6cc
5 changed files with 95 additions and 131 deletions
+7 -7
View File
@@ -497,7 +497,7 @@ func addCommentToTree(pc *PostAndComments, comment *Comment) {
}
}
func (s *PostService) random(ctx context.Context, subreddits ...string) (*Post, []*Comment, *Response, error) {
func (s *PostService) random(ctx context.Context, subreddits ...string) (*PostAndComments, *Response, error) {
path := "random"
if len(subreddits) > 0 {
path = fmt.Sprintf("r/%s/random", strings.Join(subreddits, "+"))
@@ -505,30 +505,30 @@ func (s *PostService) random(ctx context.Context, subreddits ...string) (*Post,
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
root := new(PostAndComments)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, nil, resp, err
return nil, resp, err
}
return root.Post, root.Comments, resp, nil
return root, resp, nil
}
// RandomFromSubreddits returns a random post and its comments from the subreddits.
// If no subreddits are provided, Reddit runs the query against your subscriptions.
func (s *PostService) RandomFromSubreddits(ctx context.Context, subreddits ...string) (*Post, []*Comment, *Response, error) {
func (s *PostService) RandomFromSubreddits(ctx context.Context, subreddits ...string) (*PostAndComments, *Response, error) {
return s.random(ctx, subreddits...)
}
// Random returns a random post and its comments from all of Reddit.
func (s *PostService) Random(ctx context.Context) (*Post, []*Comment, *Response, error) {
func (s *PostService) Random(ctx context.Context) (*PostAndComments, *Response, error) {
return s.random(ctx, "all")
}
// RandomFromSubscriptions returns a random post and its comments from your subscriptions.
func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*Post, []*Comment, *Response, error) {
func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*PostAndComments, *Response, error) {
return s.random(ctx)
}