This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask_test.go
85 lines (83 loc) · 1.93 KB
/
task_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 api
import "testing"
func Test_taskUrl(t *testing.T) {
type args struct {
c Connection
p TaskParams
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "All Tasks",
args: args{
c: Connection{ApiUrl: "http://apiurl", Token: "TOKEN"},
p: TaskParams{
OnlyArchivedTasks: false,
OnlyActiveTasks: false,
},
},
want: "http://apiurl/tasks/format/json/api_token/TOKEN?",
wantErr: false,
}, {
name: "Archived Tasks Filter",
args: args{
c: Connection{ApiUrl: "http://apiurl", Token: "TOKEN"},
p: TaskParams{
OnlyArchivedTasks: true,
OnlyActiveTasks: false,
},
},
want: "http://apiurl/tasks/format/json/api_token/TOKEN?exclude_archived=1",
wantErr: false,
}, {
name: "Active Tasks Filter",
args: args{
c: Connection{ApiUrl: "http://apiurl", Token: "TOKEN"},
p: TaskParams{
OnlyArchivedTasks: false,
OnlyActiveTasks: true,
},
},
want: "http://apiurl/tasks/format/json/api_token/TOKEN?exclude_archived=0",
wantErr: false,
}, {
name: "Too Many Filters",
args: args{
c: Connection{ApiUrl: "http://apiurl", Token: "TOKEN"},
p: TaskParams{
OnlyArchivedTasks: true,
OnlyActiveTasks: true,
},
},
want: "",
wantErr: true,
}, {
name: "URL Character Quoting",
args: args{
c: Connection{ApiUrl: "apiurl//{query}[#]", Token: "TOKEN"},
p: TaskParams{
OnlyArchivedTasks: false,
OnlyActiveTasks: false,
},
},
want: "apiurl//%7Bquery%7D%5B#]/tasks/format/json/api_token/TOKEN?",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := taskUrl(tt.args.c, tt.args.p)
if (err != nil) != tt.wantErr {
t.Errorf("taskUrl() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("taskUrl() got = %v, want %v", got, tt.want)
}
})
}
}