This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
users_test.go
139 lines (119 loc) · 3.62 KB
/
users_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package gostagram
import (
"testing"
)
var (
// basic variables to create
// an instagram client.
clientId = ""
clientSecret = ""
accessToken = ""
useSignedRequest = false
other_user_id = ""
user_query = ""
)
func CreateClient(t *testing.T) *Client {
FatalIfEmptyString(clientSecret, "Access token not set.", t)
client := NewClient(accessToken)
if useSignedRequest {
client.SetSignedRequest(true)
FatalIfEmptyString(clientSecret, "Client secret not set and is need it for signed request.", t)
client.SetClientSecret(clientSecret)
client.SetClientId(clientId)
}
return client
}
// throw an error, if an error exists.
func PanicIfError(err error, t *testing.T) {
if err != nil {
t.Fatal(err)
}
}
// throw an error if b string is empty.
func FatalIfEmptyString(b, errMessage string, t *testing.T) {
if len(b) == 0 {
t.Fatal(errMessage)
}
}
// will replace empty string by 'None'
func DefaultStringValueIfEmpty(t string) string {
if len(t) > 0 {
return t
}
return "None"
}
func LogUserDetailed(user *UserDetailed, t *testing.T) {
t.Log("------------------ Start User ------------------")
t.Log("Username: ", DefaultStringValueIfEmpty(user.Username))
t.Log("Profile Picture: ", DefaultStringValueIfEmpty(user.ProfilePicture))
t.Log("Fullname: ", DefaultStringValueIfEmpty(user.FullName))
t.Log("Website: ", DefaultStringValueIfEmpty(user.Website))
t.Log("Bio: ", DefaultStringValueIfEmpty(user.Bio))
t.Log("Id: ", DefaultStringValueIfEmpty(user.Id))
t.Log("Followed by: ", user.Counts.FollowedBy)
t.Log("Follows: ", user.Counts.Follows)
t.Log("Media: ", user.Counts.Media)
t.Log("------------------ End User ------------------")
}
func LogUser(user *User, t *testing.T) {
t.Log("Username: ", DefaultStringValueIfEmpty(user.Username))
t.Log("Profile Picture: ", DefaultStringValueIfEmpty(user.ProfilePicture))
t.Log("First Name: ", DefaultStringValueIfEmpty(user.FirstName))
t.Log("Last Name: ", DefaultStringValueIfEmpty(user.LastName))
t.Log("Id: ", DefaultStringValueIfEmpty(user.Id))
t.Log("Type: ", DefaultStringValueIfEmpty(user.Type))
}
func IterateUsers(users []*User, t *testing.T) {
if len(users) > 0 {
for _, user := range users {
t.Log("------------------ Start User ------------------")
LogUser(user, t)
t.Log("------------------ End User ------------------")
}
} else {
t.Log("Not users found.!")
}
}
func TestClient_GetCurrentUser(t *testing.T) {
client := CreateClient(t)
tmp, err := client.GetCurrentUser()
PanicIfError(err, t)
LogUserDetailed(tmp, t)
}
func TestClient_GetUser(t *testing.T) {
FatalIfEmptyString(other_user_id, "user id cannot be empty.", t)
client := CreateClient(t)
tmp, err := client.GetUser(other_user_id)
PanicIfError(err, t)
LogUserDetailed(tmp, t)
}
func TestClient_SearchUsers(t *testing.T) {
client := CreateClient(t)
users, err := client.SearchUsers(user_query, nil)
PanicIfError(err, t)
IterateUsers(users, t)
}
func TestClient_SearchUsers2(t *testing.T) {
client := CreateClient(t)
users, err := client.SearchUsers(user_query, Parameters{"count": "2"})
PanicIfError(err, t)
IterateUsers(users, t)
}
func TestClient_GetCurrentUserFollows(t *testing.T) {
client := CreateClient(t)
users, err := client.GetCurrentUserFollows()
PanicIfError(err, t)
IterateUsers(users, t)
}
func TestClient_GetCurrentUserFollowedBy(t *testing.T) {
client := CreateClient(t)
users, err := client.GetCurrentUserFollowedBy()
PanicIfError(err, t)
IterateUsers(users, t)
}
func TestClient_GetCurrentUserRequestedBy(t *testing.T) {
client := CreateClient(t)
users, err := client.GetCurrentUserRequestedBy()
PanicIfError(err, t)
IterateUsers(users, t)
}