-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
93 lines (70 loc) · 1.77 KB
/
main_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
package GTCHA
import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"code.google.com/p/appengine-go/appengine/aetest"
)
func TestRegisterApp(t *testing.T) {
inst, err := aetest.NewInstance(nil)
if err != nil {
t.Fatalf("Failed to create instance: %v", err)
}
defer inst.Close()
req, err := inst.NewRequest("POST", "/register", nil)
if err != nil {
t.Fatal(err)
}
req.PostForm = url.Values{}
req.PostForm.Set("name", "bizzle")
req.PostForm.Add("domain", "http://bowery.io/wut/up")
rec := httptest.NewRecorder()
registerApp(rec, req)
if rec.Code != http.StatusOK {
t.Fatal("bad status code")
}
decoder := json.NewDecoder(rec.Body)
app := new(GtchaApp)
if err = decoder.Decode(app); err != nil {
t.Fatal(err)
}
if app.Name != "bizzle" {
t.Fatalf("expected app name %s, got %s", "bizzle", app.Name)
}
if n, a := len(app.Domains), 1; n != a {
t.Fatalf("expected %d domains, got %d", n, a)
}
if app.Secret == "" {
t.Fatal("empty app secret")
}
if app.APIKey == "" {
t.Fatal("empty api key")
}
req, err = inst.NewRequest("POST", "/register", nil)
if err != nil {
t.Fatal(err)
}
req.PostForm = url.Values{}
req.PostForm.Add("domain", "http://bowery.io/")
rec = httptest.NewRecorder()
registerApp(rec, req)
if rec.Code == http.StatusOK {
t.Fatal("should have returned error")
}
req, err = inst.NewRequest("POST", "/register", nil)
if err != nil {
t.Fatal(err)
}
req.PostForm = url.Values{}
req.PostForm.Set("name", "dat app")
rec = httptest.NewRecorder()
registerApp(rec, req)
if rec.Code == http.StatusOK {
t.Fatal("should have returned error")
}
}
// TODO: these two can't be written until we have the endpoints from giphy
func TestGetCaptcha(t *testing.T) {}
func TestVerifySession(t *testing.T) {}