forked from jschoedt/go-firestorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
46 lines (34 loc) · 1.04 KB
/
setup.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
package firestormtests
import (
"context"
"io/ioutil"
"testing"
firebase "firebase.google.com/go"
"github.com/darmie/go-firestorm"
"google.golang.org/api/option"
)
var fsc *firestorm.FSClient
func init() {
ctx := context.Background()
b, _ := ioutil.ReadFile("../auth/sn-dev.json")
app, _ := firebase.NewApp(ctx, nil, option.WithCredentialsJSON(b))
dbClient, _ := app.Firestore(ctx)
fsc = firestorm.New(dbClient, "ID", "")
}
func testRunner(t *testing.T, f func(ctx context.Context, t *testing.T)) {
f(context.Background(), t)
f(createSessionCacheContext(), t)
}
func cleanup(entities ...interface{}) {
fsc.NewRequest().DeleteEntities(context.Background(), entities)()
}
func createSessionCacheContext() context.Context {
ctx := context.Background()
return context.WithValue(ctx, firestorm.SessionCacheKey, make(map[string]firestorm.EntityMap))
}
func getSessionCache(ctx context.Context) map[string]firestorm.EntityMap {
if c, ok := ctx.Value(firestorm.SessionCacheKey).(map[string]firestorm.EntityMap); ok {
return c
}
return nil
}