-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatabase_test.go
122 lines (119 loc) · 3.06 KB
/
database_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
117
118
119
120
121
122
package firebase
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/kubemq-io/kubemq-targets/config"
"github.com/kubemq-io/kubemq-targets/types"
"github.com/stretchr/testify/require"
)
func TestClient_db(t *testing.T) {
dat, err := getTestStructure()
require.NoError(t, err)
cfg := config.Spec{
Name: "gcp-firebase",
Kind: "gcp.firebase",
Properties: map[string]string{
"project_id": dat.projectID,
"credentials": dat.cred,
"db_client": "true",
"db_url": dat.dbName,
"auth_client": "false",
"messaging_client": "false",
},
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
c := New()
err = c.Init(ctx, cfg, nil)
require.NoError(t, err)
m := make(map[string]interface{})
m["some_key"] = "some_value"
b, err := json.Marshal(m)
require.NoError(t, err)
m2 := make(map[string]interface{})
m2["some_key"] = "some_value_new"
b2, err := json.Marshal(m2)
require.NoError(t, err)
k := "newValue1"
bk1, err := json.Marshal(k)
require.NoError(t, err)
k2 := "newValue2"
bk2, err := json.Marshal(k2)
require.NoError(t, err)
tests := []struct {
name string
wantErr bool
request *types.Request
}{
{
name: "valid db-get",
request: types.NewRequest().
SetMetadataKeyValue("method", "get_db").
SetMetadataKeyValue("ref_path", "test"),
wantErr: false,
},
{
name: "valid db-set - no child ref",
request: types.NewRequest().
SetMetadataKeyValue("method", "set_db").
SetMetadataKeyValue("ref_path", "test").
SetData(bk1),
wantErr: false,
},
{
name: "valid db-set - child ref",
request: types.NewRequest().
SetMetadataKeyValue("method", "set_db").
SetMetadataKeyValue("ref_path", "test").
SetMetadataKeyValue("child_ref", "test_child_ref").
SetData(bk2),
wantErr: false,
},
{
name: "valid db-update- no child ref",
request: types.NewRequest().
SetMetadataKeyValue("method", "update_db").
SetMetadataKeyValue("ref_path", "test").
SetData(b),
wantErr: false,
},
{
name: "valid db-update - child ref ",
request: types.NewRequest().
SetMetadataKeyValue("method", "update_db").
SetMetadataKeyValue("ref_path", "test").
SetMetadataKeyValue("child_ref", "test_child_ref").
SetData(b2),
wantErr: false,
},
{
name: "valid db-update - child ref ",
request: types.NewRequest().
SetMetadataKeyValue("method", "delete_db").
SetMetadataKeyValue("ref_path", "test").
SetMetadataKeyValue("child_ref", "test_child_ref"),
wantErr: false,
},
{
name: "valid db-update - no child ref ",
request: types.NewRequest().
SetMetadataKeyValue("method", "delete_db").
SetMetadataKeyValue("ref_path", "test"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r, err := c.Do(ctx, tt.request)
if tt.wantErr {
require.Error(t, err)
t.Logf("init() error = %v, wantSetErr %v", err, tt.wantErr)
return
}
require.NoError(t, err)
t.Logf("received response: %s for test: %s", r.Data, tt.name)
})
}
}