-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlink_test.go
85 lines (70 loc) · 2.28 KB
/
link_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package reddit
import (
"fmt"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDeleteLink(t *testing.T) {
url := fmt.Sprintf("%s/api/del", baseAuthURL)
httpmock.Activate()
httpmock.RegisterResponder("POST", url, httpmock.NewStringResponder(200, "{}"))
defer httpmock.DeactivateAndReset()
client := NoAuthClient
err := client.DeleteLink("5ans3h")
assert.NoError(t, err)
}
func TestCommentOnLink(t *testing.T) {
url := fmt.Sprintf("%s/api/comment", baseAuthURL)
httpmock.Activate()
httpmock.RegisterResponder("POST", url, httpmock.NewStringResponder(200, "{}"))
defer httpmock.DeactivateAndReset()
client := NoAuthClient
err := client.CommentOnLink("5ans3h", "Hello World!")
assert.NoError(t, err)
}
func TestEditLinkText(t *testing.T) {
url := fmt.Sprintf("%s/api/editusertext", baseAuthURL)
httpmock.Activate()
httpmock.RegisterResponder("POST", url, httpmock.NewStringResponder(200, "{}"))
defer httpmock.DeactivateAndReset()
client := NoAuthClient
err := client.EditLinkText("5ans3h", "Hello World!")
assert.NoError(t, err)
}
func TestGetHotLinks(t *testing.T) {
url := fmt.Sprintf("%s/r/news/hot.json", baseURL)
mockResponseFromFile(url, "test_data/link/hot_links.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
links, err := client.GetHotLinks("news")
assert.NoError(t, err)
assert.Equal(t, len(links), 3)
}
func TestGetNewLinks(t *testing.T) {
url := fmt.Sprintf("%s/r/news/new.json", baseURL)
mockResponseFromFile(url, "test_data/link/new_links.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
links, err := client.GetNewLinks("news")
assert.NoError(t, err)
assert.Equal(t, len(links), 3)
}
func TestGetTopLinks(t *testing.T) {
url := fmt.Sprintf("%s/r/news/top.json", baseURL)
mockResponseFromFile(url, "test_data/link/top_links.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
links, err := client.GetTopLinks("news")
assert.NoError(t, err)
assert.Equal(t, len(links), 3)
}
func TestHideLink(t *testing.T) {
url := fmt.Sprintf("%s/api/hide", baseAuthURL)
httpmock.Activate()
httpmock.RegisterResponder("POST", url, httpmock.NewStringResponder(200, "{}"))
defer httpmock.DeactivateAndReset()
client := NoAuthClient
err := client.HideLink("5ans3h")
assert.NoError(t, err)
}