-
Notifications
You must be signed in to change notification settings - Fork 7
/
metadata_test.go
186 lines (182 loc) · 4.59 KB
/
metadata_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package bigtable
import (
"testing"
"github.com/kubemq-io/kubemq-targets/config"
"github.com/kubemq-io/kubemq-targets/types"
"github.com/stretchr/testify/require"
)
func TestParseMetaData(t *testing.T) {
dat, err := getTestStructure()
require.NoError(t, err)
tests := []struct {
name string
cfg config.Spec
wantErr bool
Request *types.Request
}{
{
name: "valid method write",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "write").
SetMetadataKeyValue("table_name", dat.tableName).
SetMetadataKeyValue("column_family", dat.columnFamily),
wantErr: false,
},
{
name: "invalid method write - missing column_family",
cfg: config.Spec{
Name: "gcp-bigtable",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "write").
SetMetadataKeyValue("table_name", dat.tableName),
wantErr: true,
},
{
name: "valid method write_batch",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "write_batch").
SetMetadataKeyValue("table_name", dat.tableName).
SetMetadataKeyValue("column_family", dat.columnFamily),
wantErr: false,
},
{
name: "invalid method write_batch - missing column_family",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "write_batch").
SetMetadataKeyValue("table_name", dat.tableName),
wantErr: true,
},
{
name: "valid method delete_rows",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "delete_row").
SetMetadataKeyValue("table_name", dat.tableName).
SetMetadataKeyValue("row_key_prefix", dat.rowKeyPrefix),
wantErr: false,
},
{
name: "invalid method delete_row - missing row_key_prefix",
cfg: config.Spec{
Name: "gcp-bigtable",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "delete_row").
SetMetadataKeyValue("table_name", dat.tableName),
wantErr: true,
},
{
name: "valid method create_table",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "create_table").
SetMetadataKeyValue("table_name", dat.tempTable),
wantErr: false,
},
{
name: "valid method delete_table",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "delete_table").
SetMetadataKeyValue("table_name", dat.tempTable),
wantErr: false,
},
{
name: "valid method get_tables",
cfg: config.Spec{
Name: "google-big-table-target",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "get_tables"),
wantErr: false,
},
{
name: "invalid method type",
cfg: config.Spec{
Name: "gcp-bigtable",
Kind: "",
Properties: map[string]string{
"project_id": dat.projectID,
"instance": dat.instance,
},
},
Request: types.NewRequest().
SetMetadataKeyValue("method", "non_existing_type").
SetMetadataKeyValue("table_name", dat.tempTable),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m, err := parseMetadata(tt.Request.Metadata)
if tt.wantErr {
require.Error(t, err)
t.Logf("init() error = %v, wantSetErr %v", err, tt.wantErr)
return
}
require.NoError(t, err)
require.NotNil(t, m)
})
}
}