Skip to content

Commit c447e41

Browse files
committed
test for (*dict).AddPairs()
1 parent 2656b05 commit c447e41

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

internal/params/dict_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/stretchr/testify/require"
99
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
10+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
1011

1112
"github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
1213
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
@@ -403,3 +404,71 @@ func TestDict(t *testing.T) {
403404
}
404405
}
405406
}
407+
408+
func TestDict_AddPairs(t *testing.T) {
409+
a := allocator.New()
410+
defer a.Free()
411+
412+
pairs := []value.DictValueField{
413+
{
414+
K: value.Int64Value(123),
415+
V: value.BoolValue(true),
416+
},
417+
{
418+
K: value.Int64Value(321),
419+
V: value.BoolValue(false),
420+
},
421+
}
422+
423+
params := Builder{}.Param("$x").Dict().AddPairs(pairs...).Build().Build().ToYDB(a)
424+
425+
require.Equal(t, paramsToJSON(
426+
map[string]*Ydb.TypedValue{
427+
"$x": {
428+
Type: &Ydb.Type{
429+
Type: &Ydb.Type_DictType{
430+
DictType: &Ydb.DictType{
431+
Key: &Ydb.Type{
432+
Type: &Ydb.Type_TypeId{
433+
TypeId: Ydb.Type_INT64,
434+
},
435+
},
436+
Payload: &Ydb.Type{
437+
Type: &Ydb.Type_TypeId{
438+
TypeId: Ydb.Type_BOOL,
439+
},
440+
},
441+
},
442+
},
443+
},
444+
Value: &Ydb.Value{
445+
Pairs: []*Ydb.ValuePair{
446+
{
447+
Key: &Ydb.Value{
448+
Value: &Ydb.Value_Int64Value{
449+
Int64Value: 123,
450+
},
451+
},
452+
Payload: &Ydb.Value{
453+
Value: &Ydb.Value_BoolValue{
454+
BoolValue: true,
455+
},
456+
},
457+
},
458+
{
459+
Key: &Ydb.Value{
460+
Value: &Ydb.Value_Int64Value{
461+
Int64Value: 321,
462+
},
463+
},
464+
Payload: &Ydb.Value{
465+
Value: &Ydb.Value_BoolValue{
466+
BoolValue: false,
467+
},
468+
},
469+
},
470+
},
471+
},
472+
},
473+
}), paramsToJSON(params))
474+
}

internal/xtest/call_method_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestCallMethod(t *testing.T) {
3333
})
3434

3535
require.Panics(t, func() {
36-
CallMethod(object, "String", 123)
36+
// Wrong argument type.
37+
CallMethod(object, "WriteString", 123)
3738
})
3839
}

0 commit comments

Comments
 (0)