-
Notifications
You must be signed in to change notification settings - Fork 38
/
entity_parser_test.go
693 lines (611 loc) · 18.3 KB
/
entity_parser_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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package dosa
import (
"io"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type SinglePrimaryKeyNoParen struct {
Entity `dosa:"primaryKey=PrimaryKey"`
PrimaryKey int64
TData string
}
// happy path: A single primaryKey becomes the partition key
func TestSinglePrimaryKeyNoParen(t *testing.T) {
dosaTable, err := TableFromInstance(&SinglePrimaryKeyNoParen{})
assert.Nil(t, err)
assert.Equal(t, []string{"primarykey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, 0, len(dosaTable.Key.ClusteringKeys))
}
func TestNilPointer(t *testing.T) {
dosaTable, err := TableFromInstance((*SinglePrimaryKeyNoParen)(nil))
assert.Nil(t, err)
assert.Equal(t, []string{"primarykey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, 0, len(dosaTable.Key.ClusteringKeys))
}
type SinglePrimaryKey struct {
Entity `dosa:"primaryKey=(PrimaryKey)"`
PrimaryKey int64
TData string
}
// happy path: A single primaryKey becomes the partition key
func TestSinglePrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&SinglePrimaryKey{})
assert.Nil(t, err)
assert.Equal(t, []string{"primarykey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, 0, len(dosaTable.Key.ClusteringKeys))
}
func BenchmarkSingleKey(b *testing.B) {
for i := 0; i < b.N; i++ {
TableFromInstance(&SinglePrimaryKey{})
}
}
type SinglePartitionKey struct {
Entity `dosa:"primaryKey=PrimaryKey"`
PrimaryKey int64
data string
}
func TestSinglePartitionKey(t *testing.T) {
dosaTable, err := TableFromInstance(&SinglePartitionKey{})
assert.Nil(t, err)
assert.Equal(t, []string{"primarykey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, 0, len(dosaTable.Key.ClusteringKeys))
}
// unhappy path: this struct doesn't have anything specified for pk
type NoPrimaryKey struct {
Entity `dosa:"primaryKey="`
PrimaryKey int64
data string
}
// unhappy path: If there is no field marked with a primary nor partition key, throw an error
func TestNoPrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&NoPrimaryKey{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
}
// unhappy path: this struct has an empty primary key
type EmptyPrimaryKey struct {
Entity `dosa:"primaryKey=()"`
PrimaryKey int64
data string
}
// unhappy path: If there is no field marked with a primary nor partition key, throw an error
func TestEmptyPrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&EmptyPrimaryKey{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
}
type PrimaryKeyWithSecondaryRange struct {
Entity `dosa:"primaryKey=(PartKey,PrimaryKey )"`
PartKey int64
PrimaryKey int64
data, moredata string
}
func TestPrimaryKeyWithSecondaryRange(t *testing.T) {
dosaTable, err := TableFromInstance(&PrimaryKeyWithSecondaryRange{})
assert.Nil(t, err)
assert.Equal(t, []string{"partkey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, []*ClusteringKey{{"primarykey", false}}, dosaTable.Key.ClusteringKeys)
}
type PrimaryKeyWithDescendingRange struct {
Entity `dosa:"primaryKey=(PartKey,PrimaryKey desc )"`
PartKey int64
PrimaryKey int64
data string
}
func TestPrimaryKeyWithDescendingRange(t *testing.T) {
dosaTable, err := TableFromInstance(&PrimaryKeyWithDescendingRange{})
assert.Nil(t, err)
assert.Equal(t, []string{"partkey"}, dosaTable.Key.PartitionKeys)
assert.Equal(t, []*ClusteringKey{{"primarykey", true}}, dosaTable.Key.ClusteringKeys)
}
type MultiComponentPrimaryKey struct {
Entity `dosa:"primaryKey=((PartKey, AnotherPartKey))"`
PartKey int64
AnotherPartKey int64
data string
}
func TestMultiComponentPrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&MultiComponentPrimaryKey{})
assert.Nil(t, err)
assert.Equal(t, []string{"partkey", "anotherpartkey"}, dosaTable.Key.PartitionKeys)
assert.Nil(t, dosaTable.Key.ClusteringKeys)
}
type NameInPrimaryKey struct {
Entity `dosa:"name=nameinprimarykey,primaryKey=(PrimaryKey, Name)"`
PrimaryKey int64
Name string
}
func TestNameInPrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&NameInPrimaryKey{})
assert.Nil(t, err)
assert.Equal(t, "nameinprimarykey", dosaTable.Name)
}
type NoETLTag struct {
Entity `dosa:"name=noetltag,primaryKey=PrimaryKey"`
PrimaryKey int64
TData string
}
func TestNoETLTag(t *testing.T) {
dosaTable, err := TableFromInstance(&NoETLTag{})
assert.Nil(t, err)
assert.Equal(t, EtlOff, dosaTable.ETL)
}
type ETLTagOff struct {
Entity `dosa:"primaryKey=PrimaryKey, etl=off"`
PrimaryKey int64
TData string
}
func TestETLTagOff(t *testing.T) {
dosaTable, err := TableFromInstance(&ETLTagOff{})
assert.Nil(t, err)
assert.Equal(t, EtlOff, dosaTable.ETL)
}
type ETLTagOn struct {
Entity `dosa:"name=etltagon, primaryKey=PrimaryKey, etl=on"`
PrimaryKey int64
TData string
}
func TestETLTagOn(t *testing.T) {
dosaTable, err := TableFromInstance(&ETLTagOn{})
assert.Nil(t, err)
assert.Equal(t, EtlOn, dosaTable.ETL)
}
type ETLTagIncomplete struct {
Entity `dosa:"primaryKey=PrimaryKey, etl="`
PrimaryKey int64
TData string
}
func TestETLTagInComplete(t *testing.T) {
dosaTable, err := TableFromInstance(&ETLTagIncomplete{})
assert.Error(t, err)
t.Log(err)
assert.Nil(t, dosaTable)
}
type ETLTagNoMatch struct {
Entity `dosa:"primaryKey=PrimaryKey, etl"`
PrimaryKey int64
TData string
}
func TestETLTagNoMatch(t *testing.T) {
dosaTable, err := TableFromInstance(&ETLTagNoMatch{})
assert.Error(t, err)
assert.Nil(t, dosaTable)
}
type ETLInPrimaryKey struct {
Entity `dosa:"primaryKey=(PrimaryKey, Etl), etl=on"`
PrimaryKey int64
TData string
Etl string
}
func TestETLInPrimaryKey(t *testing.T) {
dosaTable, err := TableFromInstance(&ETLInPrimaryKey{})
assert.NoError(t, err)
assert.Equal(t, EtlOn, dosaTable.ETL)
}
type InvalidDosaAttribute struct {
Entity `dosa:"oopsie, primaryKey=Oops"`
Oops int64
}
func TestInvalidDosaAttribute(t *testing.T) {
dosaTable, err := TableFromInstance(&InvalidDosaAttribute{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "oopsie")
}
func TestStringify(t *testing.T) {
dosaTable, _ := TableFromInstance(&SinglePrimaryKey{})
assert.Contains(t, dosaTable.String(), dosaTable.Name)
assert.Contains(t, dosaTable.String(), "primarykey")
}
type MissingCloseParen struct {
Entity `dosa:"primaryKey=(MissingCloseParen"`
MissingCloseParen int64
}
func TestMissingCloseParen(t *testing.T) {
dosaTable, err := TableFromInstance(&MissingCloseParen{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "MissingCloseParen")
}
type MissingAnnotation struct {
Entity
Oops int64
}
func TestMissingAnnotation(t *testing.T) {
dosaTable, err := TableFromInstance(&MissingAnnotation{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "struct")
assert.Contains(t, err.Error(), "tag")
}
type AllTypes struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
Int32Type int32
Int64Type int64
DoubleType float64
StringType string
BlobType []byte
TimeType time.Time
UUIDType UUID
NullBoolType *bool
NullInt32Type *int32
NullInt64Type *int64
NullDoubleType *float64
NullStringType *string
NullTimeType *time.Time
NullUUIDType *UUID
}
func TestAllTypes(t *testing.T) {
dosaTable, err := TableFromInstance(&AllTypes{})
assert.NotNil(t, dosaTable)
assert.NoError(t, err)
cds := dosaTable.Columns
assert.Len(t, cds, 15)
for _, cd := range cds {
name, err := NormalizeName(cd.Name)
assert.NoError(t, err)
switch name {
case "booltype":
assert.Equal(t, Bool, cd.Type)
case "int32type":
assert.Equal(t, Int32, cd.Type)
case "int64type":
assert.Equal(t, Int64, cd.Type)
case "doubletype":
assert.Equal(t, Double, cd.Type)
case "stringtype":
assert.Equal(t, String, cd.Type)
case "blobtype":
assert.Equal(t, Blob, cd.Type)
case "timetype":
assert.Equal(t, Timestamp, cd.Type)
case "uuidtype":
assert.Equal(t, TUUID, cd.Type)
case "nullbooltype":
assert.Equal(t, Bool, cd.Type)
case "nullint32type":
assert.Equal(t, Int32, cd.Type)
case "nullint64type":
assert.Equal(t, Int64, cd.Type)
case "nulldoubletype":
assert.Equal(t, Double, cd.Type)
case "nullstringtype":
assert.Equal(t, String, cd.Type)
case "nulltimetype":
assert.Equal(t, Timestamp, cd.Type)
case "nulluuidtype":
assert.Equal(t, TUUID, cd.Type)
default:
assert.Fail(t, "unexpected column name", name)
}
}
}
type NullableType struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
NullBoolType *bool
NullInt32Type *int32
NullInt64Type *int64
NullDoubleType *float64
NullStringType *string
NullTimeType *time.Time
NullUUIDType *UUID
}
func TestNullableType(t *testing.T) {
dosaTable, err := TableFromInstance(&NullableType{})
assert.NoError(t, err)
assert.NotNil(t, dosaTable)
cds := dosaTable.Columns
assert.Len(t, cds, 8)
for _, cd := range cds {
name, err := NormalizeName(cd.Name)
assert.NoError(t, err)
switch name {
case "booltype":
assert.Equal(t, Bool, cd.Type)
assert.False(t, cd.IsPointer)
case "nullbooltype":
assert.Equal(t, Bool, cd.Type)
assert.True(t, cd.IsPointer)
case "nullint32type":
assert.Equal(t, Int32, cd.Type)
assert.True(t, cd.IsPointer)
case "nullint64type":
assert.Equal(t, Int64, cd.Type)
assert.True(t, cd.IsPointer)
case "nulldoubletype":
assert.Equal(t, Double, cd.Type)
assert.True(t, cd.IsPointer)
case "nullstringtype":
assert.Equal(t, String, cd.Type)
assert.True(t, cd.IsPointer)
case "nulltimetype":
assert.Equal(t, Timestamp, cd.Type)
assert.True(t, cd.IsPointer)
case "nulluuidtype":
assert.Equal(t, TUUID, cd.Type)
assert.True(t, cd.IsPointer)
default:
assert.Fail(t, "unexpected column name", name)
}
}
}
type UnsupportedType struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
UnsupType float32
}
func TestUnsupportedType(t *testing.T) {
dosaTable, err := TableFromInstance(&UnsupportedType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "float32")
assert.Contains(t, err.Error(), "UnsupType")
}
func TestNullablePrimaryKeyType(t *testing.T) {
dosaTable, err := TableFromInstance(&NullStringPrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullBoolPrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullDoublePrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullInt32PrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullInt64PrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullTimePrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
dosaTable, err = TableFromInstance(&NullUUIDPrimaryKeyType{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "primary key is of nullable type")
}
type NullStringPrimaryKeyType struct {
Entity `dosa:"primaryKey=NullStringType"`
NullStringType *string
}
type NullUUIDPrimaryKeyType struct {
Entity `dosa:"primaryKey=NullUUIDType"`
NullUUIDType *UUID
}
type NullTimePrimaryKeyType struct {
Entity `dosa:"primaryKey=NullTimeType"`
NullTimeType *time.Time
}
type NullInt64PrimaryKeyType struct {
Entity `dosa:"primaryKey=NullInt64Type"`
NullInt64Type *int64
}
type NullInt32PrimaryKeyType struct {
Entity `dosa:"primaryKey=NullInt32Type"`
NullInt32Type *int32
}
type NullDoublePrimaryKeyType struct {
Entity `dosa:"primaryKey=NullDoubleType"`
NullDoubleType *float64
}
type NullBoolPrimaryKeyType struct {
Entity `dosa:"primaryKey=NullBoolType"`
NullBoolType *bool
}
type KeyFieldNameTypo struct {
Entity `dosa:"primaryKey=BoolHype"`
BoolType bool
}
func TestKeyFieldNameTypo(t *testing.T) {
dosaTable, err := TableFromInstance(&KeyFieldNameTypo{})
assert.Nil(t, dosaTable)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "BoolHype")
}
type UnexportedFieldType struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
unexported string
unsupportedType io.Reader
}
func TestIgnoreUnexportedFields(t *testing.T) {
table, err := TableFromInstance(&UnexportedFieldType{})
assert.NoError(t, err)
assert.Len(t, table.ColToField, 1)
assert.NotContains(t, table.ColToField, "unexported")
assert.NotContains(t, table.ColToField, "unsupportedType")
assert.Len(t, table.Columns, 1)
}
type IgnoreTagType struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
Exported string `dosa:"-"`
UnsupportedType io.Reader `dosa:"-"`
}
func TestIgnoreTag(t *testing.T) {
table, err := TableFromInstance(&IgnoreTagType{})
assert.NoError(t, err)
assert.Len(t, table.ColToField, 1)
// TODO: should be checking normalized names once normalization is done
assert.NotContains(t, table.ColToField, "Exported")
assert.NotContains(t, table.ColToField, "UnsupportedType")
assert.Len(t, table.Columns, 1)
}
func TestExtraStuffInClusteringKeyDecl(t *testing.T) {
type BadClusteringKeyDefinition struct {
Entity `dosa:"primaryKey=(BoolType,StringType asc asc)"`
BoolType bool
StringType string
}
table, err := TableFromInstance(&BadClusteringKeyDefinition{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "lustering")
}
func TestDuplicateKey(t *testing.T) {
type DuplicateKeyDefinition struct {
Entity `dosa:"primaryKey=(BoolType,BoolType)"`
BoolType bool
StringType string
}
table, err := TableFromInstance(&DuplicateKeyDefinition{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "uplicate")
}
func TestInvalidStructName(t *testing.T) {
type ăBădNăme struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
}
table, err := TableFromInstance(&ăBădNăme{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid")
}
func TestInvalidFieldInTag(t *testing.T) {
type HasInvalidCharInTag struct {
Entity `dosa:"primaryKey=(ABădNăme)"`
ABădNăme bool
}
table, err := TableFromInstance(&HasInvalidCharInTag{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid")
}
func TestInvalidSyntaxInTag(t *testing.T) {
type HasInvalidTagSyntax struct {
Entity `dosa:"primaryKey=((Val, Key), TS DESC"`
Val string
Key string
TS time.Time
}
table, err := TableFromInstance(&HasInvalidTagSyntax{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unmatched parentheses")
}
func TestParensBalanced(t *testing.T) {
assert.True(t, parensBalanced("()"))
assert.True(t, parensBalanced("()()"))
assert.True(t, parensBalanced("(()())"))
assert.True(t, parensBalanced("()"))
assert.True(t, parensBalanced(""))
assert.True(t, parensBalanced("()(()(()(()()))())()()"))
assert.False(t, parensBalanced("("))
assert.False(t, parensBalanced(")"))
assert.False(t, parensBalanced("(()"))
assert.False(t, parensBalanced(")("))
assert.False(t, parensBalanced("(()))"))
assert.False(t, parensBalanced("((()())"))
}
func TestGetTags(t *testing.T) {
testCases := []struct {
tag string
exp string
err string
}{
{
tag: "",
exp: "{}",
},
{
tag: "a=b",
exp: "{a: b}",
},
{
tag: "a=b,c=d",
exp: "{a: b, c: d}",
},
{
tag: " a=b , c=d",
exp: "{a: b, c: d}",
},
{
tag: "a = b,c = d ",
exp: "{a: b, c: d}",
},
{
tag: "c",
err: "invalid dosa field tag 'c'",
},
{
tag: "a=b=c",
err: "invalid dosa field tag 'a=b=c'",
},
}
for _, tc := range testCases {
tags, err := getTags(tc.tag)
if tc.err == "" {
assert.Nil(t, err)
assert.Equal(t, tc.exp, deterministicPrintMap(tags))
} else {
assert.NotNil(t, err)
assert.Contains(t, err.Error(), tc.err)
}
}
}
/*
These tests do not currently pass, but I think they should
*/
func TestRenameToInvalidName(t *testing.T) {
type InvalidRename struct {
Entity `dosa:"primaryKey=BoolType"`
BoolType bool
AGoodName string `dosa:"name=ABădNăme"`
}
table, err := TableFromInstance(&InvalidRename{})
assert.Nil(t, table)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid name")
}
type BadColNameButRenamed struct {
Entity `dosa:"primaryKey=(ABădNăme)"`
ABădNăme bool `dosa:"name=goodname"`
}
func TestRenameColumnToValidName(t *testing.T) {
table, err := TableFromInstance(&BadColNameButRenamed{})
assert.NoError(t, err)
assert.Equal(t, []string{"goodname"}, table.Key.PartitionKeys)
}
type StructWithUnannotatedEntity struct {
Entity `notdosa:"covers a rare test case"`
}
func TestRenameStructToValidName(t *testing.T) {
type ABădNăme struct {
Entity `dosa:"name=agoodname,primaryKey=Dummy"`
Dummy bool
}
table, err := TableFromInstance(&ABădNăme{})
assert.NoError(t, err)
assert.NotNil(t, table)
}