-
Notifications
You must be signed in to change notification settings - Fork 7
/
fsrpl_test.go
64 lines (55 loc) · 1.38 KB
/
fsrpl_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
package main
import (
"context"
"log"
"os"
"testing"
"time"
)
var (
fsEmulator *Firestore
testOpt = &Option{Debug: true, Stdout: os.Stdout, Stderr: os.Stderr}
// for scan tests
scanFirestorePath = "scan/"
scanDataList = map[string]map[string]interface{}{
"one": map[string]interface{}{
"string": "value",
"int": 100,
"time": time.Date(2019, time.November, 10, 23, 0, 0, 0, time.UTC),
"bool": true,
"array": []interface{}{"hoge", "fuga"},
"map": map[string]interface{}{"one": 1, "two": 2},
},
"two": map[string]interface{}{
"complex": map[string]interface{}{"one": []interface{}{"1", "11", "111"}, "two": 2},
},
}
)
func TestMain(m *testing.M) {
ctx := context.Background()
println("before all...", os.Getenv("FIRESTORE_EMULATOR_HOST"))
if err := setupEmulator(ctx); err != nil {
log.Fatalf("failed setupEmulator: %v", err)
}
// defer teardown()
os.Exit(m.Run())
}
func setupEmulator(ctx context.Context) error {
var err error
conOpt := FirestoreConnectionOption{}
fsEmulator, err = NewFirebase(ctx, testOpt, conOpt)
if err != nil {
return err
}
return fsEmulator.importTestdata()
}
func (f *Firestore) importTestdata() error {
ctx := context.Background()
for k, testData := range scanDataList {
path := scanFirestorePath + k
if err := f.SaveData(ctx, testOpt, path, testData); err != nil {
return err
}
}
return nil
}