-
Notifications
You must be signed in to change notification settings - Fork 12
/
subreddit_test.go
52 lines (43 loc) · 1.47 KB
/
subreddit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package reddit
import (
"fmt"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetDefaultSubreddits(t *testing.T) {
url := fmt.Sprintf("%s/subreddits/default.json", baseURL)
mockResponseFromFile(url, "test_data/subreddit/default_subreddits.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
subreddits, err := client.GetDefaultSubreddits()
assert.NoError(t, err)
assert.Equal(t, len(subreddits), 3, t)
}
func TestGetGoldSubreddits(t *testing.T) {
url := fmt.Sprintf("%s/subreddits/gold.json", baseURL)
mockResponseFromFile(url, "test_data/subreddit/gold_subreddits.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
subreddits, err := client.GetGoldSubreddits()
assert.NoError(t, err)
assert.Equal(t, len(subreddits), 0)
}
func TestGetNewSubreddits(t *testing.T) {
url := fmt.Sprintf("%s/subreddits/new.json", baseURL)
mockResponseFromFile(url, "test_data/subreddit/new_subreddits.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
subreddits, err := client.GetNewSubreddits()
assert.NoError(t, err)
assert.Equal(t, len(subreddits), 3)
}
func TestGetPopularSubreddits(t *testing.T) {
url := fmt.Sprintf("%s/subreddits/popular.json", baseURL)
mockResponseFromFile(url, "test_data/subreddit/popular_subreddits.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
subreddits, err := client.GetPopularSubreddits()
assert.NoError(t, err)
assert.Equal(t, len(subreddits), 3)
}