Skip to content

Commit 56613fb

Browse files
committed
new types for set + tests
1 parent d588f35 commit 56613fb

File tree

3 files changed

+174
-3
lines changed

3 files changed

+174
-3
lines changed

internal/params/list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func TestList(t *testing.T) {
527527
},
528528
{
529529
name: xtest.CurrentFileLine(),
530-
builder: Builder{}.Param("$x").List().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(), //nolint:lll
530+
builder: Builder{}.Param("$x").List().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(),
531531
params: map[string]*Ydb.TypedValue{
532532
"$x": {
533533
Type: &Ydb.Type{
@@ -555,7 +555,7 @@ func TestList(t *testing.T) {
555555
},
556556
{
557557
name: xtest.CurrentFileLine(),
558-
builder: Builder{}.Param("$x").List().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(), //nolint:lll
558+
builder: Builder{}.Param("$x").List().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(),
559559
params: map[string]*Ydb.TypedValue{
560560
"$x": {
561561
Type: &Ydb.Type{
@@ -583,7 +583,7 @@ func TestList(t *testing.T) {
583583
},
584584
{
585585
name: xtest.CurrentFileLine(),
586-
builder: Builder{}.Param("$x").List().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(), //nolint:lll
586+
builder: Builder{}.Param("$x").List().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(),
587587
params: map[string]*Ydb.TypedValue{
588588
"$x": {
589589
Type: &Ydb.Type{

internal/params/set.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,27 @@ func (s *setItem) Interval(v time.Duration) *set {
141141

142142
return s.parent
143143
}
144+
145+
func (s *setItem) JSON(v string) *set {
146+
s.parent.values = append(s.parent.values, value.JSONValue(v))
147+
148+
return s.parent
149+
}
150+
151+
func (s *setItem) JSONDocument(v string) *set {
152+
s.parent.values = append(s.parent.values, value.JSONDocumentValue(v))
153+
154+
return s.parent
155+
}
156+
157+
func (s *setItem) YSON(v []byte) *set {
158+
s.parent.values = append(s.parent.values, value.YSONValue(v))
159+
160+
return s.parent
161+
}
162+
163+
func (s *setItem) UUID(v [16]byte) *set {
164+
s.parent.values = append(s.parent.values, value.UUIDValue(v))
165+
166+
return s.parent
167+
}

internal/params/set_test.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,153 @@ func TestSet(t *testing.T) {
669669
},
670670
},
671671
},
672+
{
673+
name: xtest.CurrentFileLine(),
674+
builder: Builder{}.Param("$x").Set().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(),
675+
params: map[string]*Ydb.TypedValue{
676+
"$x": {
677+
Type: &Ydb.Type{
678+
Type: &Ydb.Type_DictType{
679+
DictType: &Ydb.DictType{
680+
Key: &Ydb.Type{
681+
Type: &Ydb.Type_TypeId{
682+
TypeId: Ydb.Type_JSON,
683+
},
684+
},
685+
Payload: &Ydb.Type{
686+
Type: &Ydb.Type_VoidType{},
687+
},
688+
},
689+
},
690+
},
691+
Value: &Ydb.Value{
692+
Pairs: []*Ydb.ValuePair{
693+
{
694+
Key: &Ydb.Value{
695+
Value: &Ydb.Value_TextValue{
696+
TextValue: `{"a": 1,"b": "B"}`,
697+
},
698+
},
699+
Payload: &Ydb.Value{
700+
Value: &Ydb.Value_NullFlagValue{},
701+
},
702+
},
703+
},
704+
},
705+
},
706+
},
707+
},
708+
{
709+
name: xtest.CurrentFileLine(),
710+
builder: Builder{}.Param("$x").Set().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(),
711+
params: map[string]*Ydb.TypedValue{
712+
"$x": {
713+
Type: &Ydb.Type{
714+
Type: &Ydb.Type_DictType{
715+
DictType: &Ydb.DictType{
716+
Key: &Ydb.Type{
717+
Type: &Ydb.Type_TypeId{
718+
TypeId: Ydb.Type_JSON_DOCUMENT,
719+
},
720+
},
721+
Payload: &Ydb.Type{
722+
Type: &Ydb.Type_VoidType{},
723+
},
724+
},
725+
},
726+
},
727+
Value: &Ydb.Value{
728+
Pairs: []*Ydb.ValuePair{
729+
{
730+
Key: &Ydb.Value{
731+
Value: &Ydb.Value_TextValue{
732+
TextValue: `{"a": 1,"b": "B"}`,
733+
},
734+
},
735+
Payload: &Ydb.Value{
736+
Value: &Ydb.Value_NullFlagValue{},
737+
},
738+
},
739+
},
740+
},
741+
},
742+
},
743+
},
744+
{
745+
name: xtest.CurrentFileLine(),
746+
builder: Builder{}.Param("$x").Set().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(),
747+
params: map[string]*Ydb.TypedValue{
748+
"$x": {
749+
Type: &Ydb.Type{
750+
Type: &Ydb.Type_DictType{
751+
DictType: &Ydb.DictType{
752+
Key: &Ydb.Type{
753+
Type: &Ydb.Type_TypeId{
754+
TypeId: Ydb.Type_YSON,
755+
},
756+
},
757+
Payload: &Ydb.Type{
758+
Type: &Ydb.Type_VoidType{},
759+
},
760+
},
761+
},
762+
},
763+
Value: &Ydb.Value{
764+
Pairs: []*Ydb.ValuePair{
765+
{
766+
Key: &Ydb.Value{
767+
Value: &Ydb.Value_BytesValue{
768+
BytesValue: []byte(`[ 1; 2; 3; 4; 5 ]`),
769+
},
770+
},
771+
Payload: &Ydb.Value{
772+
Value: &Ydb.Value_NullFlagValue{},
773+
},
774+
},
775+
},
776+
},
777+
},
778+
},
779+
},
780+
{
781+
name: xtest.CurrentFileLine(),
782+
builder: Builder{}.Param("$x").Set().AddItem().
783+
UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}).
784+
Build(),
785+
params: map[string]*Ydb.TypedValue{
786+
"$x": {
787+
Type: &Ydb.Type{
788+
Type: &Ydb.Type_DictType{
789+
DictType: &Ydb.DictType{
790+
Key: &Ydb.Type{
791+
Type: &Ydb.Type_TypeId{
792+
TypeId: Ydb.Type_UUID,
793+
},
794+
},
795+
Payload: &Ydb.Type{
796+
Type: &Ydb.Type_VoidType{},
797+
},
798+
},
799+
},
800+
},
801+
Value: &Ydb.Value{
802+
Pairs: []*Ydb.ValuePair{
803+
{
804+
Key: &Ydb.Value{
805+
Value: &Ydb.Value_Low_128{
806+
Low_128: 651345242494996240,
807+
},
808+
High_128: 72623859790382856,
809+
},
810+
Payload: &Ydb.Value{
811+
Value: &Ydb.Value_NullFlagValue{},
812+
},
813+
},
814+
},
815+
},
816+
},
817+
},
818+
},
672819
} {
673820
t.Run(tt.name, func(t *testing.T) {
674821
a := allocator.New()

0 commit comments

Comments
 (0)