forked from ihoukai/parse-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
85 lines (73 loc) · 2.39 KB
/
delete_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 parse
import (
"fmt"
"net/http"
"testing"
)
func TestDeleteRequiresPointer(t *testing.T) {
u := User{}
expected := "v must be a non-nil pointer"
if err := Delete(u, true); err == nil {
t.Error("Delete should return an error when argument is not a pointer")
} else if err.Error() != expected {
t.Errorf("Unexpected error message. Got [%s] expected [%s]\n", err, expected)
}
if err := Delete(u, false); err == nil {
t.Error("Delete should return an error when argument is not a pointer")
} else if err.Error() != expected {
t.Errorf("Unexpected error message. Got [%s] expected [%s]\n", err, expected)
}
}
func TestEndpointDelete(t *testing.T) {
testCases := []struct {
inst interface{}
id string
expected string
}{
{&User{Base: Base{Id: "UserId1"}}, "UserId1", "https://api.parse.com/1/users/UserId1"},
{&CustomClass{Base{Id: "Custom1"}}, "Custom1", "https://api.parse.com/1/classes/CustomClass/Custom1"},
{&CustomClassCustomName{Base{Id: "CC2"}}, "CC2", "https://api.parse.com/1/classes/customName/CC2"},
{&CustomClassCustomEndpoint{Base{Id: "Cc3"}}, "Cc3", "https://api.parse.com/1/custom/class/endpoint/Cc3"},
}
for _, tc := range testCases {
d := deleteT{inst: tc.inst}
actual, err := d.endpoint()
if err != nil {
t.Errorf("Unexpected error creating query: %v\n", err)
continue
}
if actual != tc.expected {
t.Errorf("Wrong endpoint generated. Expected [%s] got [%s]\n", tc.expected, actual)
}
}
}
func TestDelete(t *testing.T) {
shouldHaveMasterKey := false
setupTestServer(func(w http.ResponseWriter, r *http.Request) {
if h := r.Header.Get(AppIdHeader); h != "app_id" {
t.Errorf("request did not have App ID header set!")
}
if h := r.Header.Get(SessionTokenHeader); h != "" {
t.Errorf("request had Session Token header set!")
}
if shouldHaveMasterKey {
if h := r.Header.Get(RestKeyHeader); h != "" {
t.Errorf("request had Rest Key header set!")
}
if h := r.Header.Get(MasterKeyHeader); h != "master_key" {
t.Errorf("request did not have Master Key header set!")
}
} else {
if h := r.Header.Get(RestKeyHeader); h != "rest_key" {
t.Errorf("request did not have Rest Key header set!")
}
if h := r.Header.Get(MasterKeyHeader); h != "" {
t.Errorf("request had Master Key header set!")
}
}
fmt.Fprintf(w, "")
})
defer teardownTestServer()
u := User{Base: Base{Id: "abc"}}
Delete(&u, false)
}