-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl_test.go
More file actions
46 lines (37 loc) · 977 Bytes
/
repl_test.go
File metadata and controls
46 lines (37 loc) · 977 Bytes
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 fscli
import (
"bytes"
"context"
"os"
"testing"
"time"
"cloud.google.com/go/firestore"
"github.com/stretchr/testify/assert"
)
func TestRepl_ProcessLineFromPipe(t *testing.T) {
os.Setenv("FIRESTORE_EMULATOR_HOST", "127.0.0.1:8080")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
fs, err := firestore.NewClient(ctx, "fscli-repl-test")
if err != nil {
t.Fatal(err)
}
defer fs.Close()
// Seed data
docRef := fs.Collection("users").Doc("testuser")
_, err = docRef.Set(ctx, map[string]interface{}{
"name": "test user",
"age": 30,
})
if err != nil {
t.Fatal(err)
}
defer docRef.Delete(ctx)
var stdin bytes.Buffer
var stdout bytes.Buffer
stdin.Write([]byte("GET users/testuser\n"))
repl := NewRepl(ctx, fs, &stdin, &stdout, OutputModeJSON)
repl.ProcessLineFromPipe()
expectedJSON := `{"id":"testuser","data":{"age":30,"name":"test user"}}`
assert.JSONEq(t, expectedJSON, stdout.String())
}