forked from g8rswimmer/go-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compliance_batch_obj_test.go
166 lines (162 loc) · 4.54 KB
/
compliance_batch_obj_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package twitter
import (
"context"
"io"
"log"
"net/http"
"reflect"
"strings"
"testing"
)
func TestComplianceBatchJobObj_Upload(t *testing.T) {
type fields struct {
UploadURL string
client *http.Client
}
type args struct {
ids io.Reader
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "success",
fields: fields{
UploadURL: "https://wwww.test.com/update",
client: mockHTTPClient(func(req *http.Request) *http.Response {
if req.Method != http.MethodPut {
log.Panicf("the method is not correct %s %s", req.Method, http.MethodPut)
}
if strings.Contains(req.URL.String(), "https://wwww.test.com/update") == false {
log.Panicf("the url is not correct %s %s", req.URL.String(), "https://wwww.test.com/update")
}
body := ``
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(body)),
Header: func() http.Header {
h := http.Header{}
h.Add(rateLimit, "15")
h.Add(rateRemaining, "12")
h.Add(rateReset, "1644461060")
return h
}(),
}
}),
},
args: args{
ids: func() io.Reader {
data := `1
2
3`
return strings.NewReader(data)
}(),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := ComplianceBatchJobObj{
UploadURL: tt.fields.UploadURL,
client: tt.fields.client,
}
if err := c.Upload(context.Background(), tt.args.ids); (err != nil) != tt.wantErr {
t.Errorf("ComplianceBatchJobObj.Upload() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestComplianceBatchJobObj_Download(t *testing.T) {
type fields struct {
DownloadURL string
client *http.Client
}
tests := []struct {
name string
fields fields
want *ComplianceBatchJobDownloadResponse
wantErr bool
}{
{
name: "success",
fields: fields{
DownloadURL: "https://wwww.test.com/download",
client: mockHTTPClient(func(req *http.Request) *http.Response {
if req.Method != http.MethodGet {
log.Panicf("the method is not correct %s %s", req.Method, http.MethodGet)
}
if strings.Contains(req.URL.String(), "https://wwww.test.com/download") == false {
log.Panicf("the url is not correct %s %s", req.URL.String(), "https://wwww.test.com/download")
}
results := `{"id":"1265324480517361664","action":"delete","created_at":"2019-10-29T17:02:47.000Z","redacted_at":"2020-07-29T17:02:47.000Z","reason":"deleted"}`
results += "\r\n"
results += `{"id":"1263926741774581761","action":"delete","created_at":"2019-10-29T17:02:47.000Z","redacted_at":"2020-07-29T17:02:47.000Z","reason":"protected"}`
results += "\r\n"
results += `{"id":"1265324480517361669","action":"delete","created_at":"2019-10-29T17:02:47.000Z","redacted_at":"2020-07-29T17:02:47.000Z","reason":"suspended"}`
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(results)),
Header: func() http.Header {
h := http.Header{}
h.Add(rateLimit, "15")
h.Add(rateRemaining, "12")
h.Add(rateReset, "1644461060")
return h
}(),
}
}),
},
want: &ComplianceBatchJobDownloadResponse{
Results: []*ComplianceBatchJobResult{
{
ID: "1265324480517361664",
Action: "delete",
CreatedAt: "2019-10-29T17:02:47.000Z",
RedactedAt: "2020-07-29T17:02:47.000Z",
Reason: "deleted",
},
{
ID: "1263926741774581761",
Action: "delete",
CreatedAt: "2019-10-29T17:02:47.000Z",
RedactedAt: "2020-07-29T17:02:47.000Z",
Reason: "protected",
},
{
ID: "1265324480517361669",
Action: "delete",
CreatedAt: "2019-10-29T17:02:47.000Z",
RedactedAt: "2020-07-29T17:02:47.000Z",
Reason: "suspended",
},
},
RateLimit: &RateLimit{
Limit: 15,
Remaining: 12,
Reset: Epoch(1644461060),
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := ComplianceBatchJobObj{
DownloadURL: tt.fields.DownloadURL,
client: tt.fields.client,
}
got, err := c.Download(context.Background())
if (err != nil) != tt.wantErr {
t.Errorf("ComplianceBatchJobObj.Download() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ComplianceBatchJobObj.Download() = %v, want %v", got, tt.want)
}
})
}
}