-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_test.go
116 lines (95 loc) · 2.15 KB
/
storage_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
package GTCHA
import (
"encoding/json"
"testing"
"time"
"code.google.com/p/appengine-go/appengine/aetest"
"github.com/pborman/uuid"
"appengine/datastore"
"appengine/memcache"
)
func TestGetApp(t *testing.T) {
domains := []string{"bowery.io"}
c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()
key := datastore.NewKey(c, "GtchaApp", uuid.New(), 0, nil)
app := &GtchaApp{
Name: "testApp",
Secret: key.StringID(),
APIKey: uuid.New(),
Domains: domains,
}
if _, err := datastore.Put(c, key, app); err != nil {
t.Fatal(err)
}
// increases likelihood that app goes in the datastore before call to Get
<-time.After(500 * time.Millisecond)
retApp, err := GetApp(c, app.APIKey, "bowery.io")
if err != nil {
t.Fatal(err)
}
if retApp.Secret != app.Secret {
t.Fatalf(
"returned app differs from expected app:\nreturned %#v\nexpected %#v",
retApp, app,
)
}
}
func TestGetGtcha(t *testing.T) {
c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()
id := "testID"
if err = SaveGtcha(c, g, id); err != nil {
t.Fatal(err)
}
retG, err := GetGtcha(c, id)
if err != nil {
t.Fatal(err)
}
for i := range g.In {
if g.In[i] != retG.In[i] {
t.Fatalf("expected same string %s, got %s", g.In[i], retG.In[i])
}
}
}
func TestSaveGtcha(t *testing.T) {
c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()
id := "testID"
if err = SaveGtcha(c, g, id); err != nil {
t.Fatal(err)
}
item, err := memcache.Get(c, "Gtcha"+id)
if err != nil {
t.Fatal(err)
}
retG := new(gtcha)
if err = json.Unmarshal(item.Value, retG); err != nil {
t.Fatal(err)
}
for i := range g.In {
if g.In[i] != retG.In[i] {
t.Fatalf("expected same string %s, got %s", g.In[i], retG.In[i])
}
}
key := datastore.NewKey(c, "Gtcha", id, 0, nil)
if err := datastore.Get(c, key, retG); err != nil {
t.Fatal(err)
}
for i := range g.In {
if g.In[i] != retG.In[i] {
t.Fatalf("expected same string %s, got %s", g.In[i], retG.In[i])
}
}
}
func TestCacheImageURI(t *testing.T) { t.Log("TODO") }
func TestGetImageURI(t *testing.T) { t.Log("TODO") }