PK���ȼRY��������€��� �v3.phpUT �øŽg‰gñ“gux �õ��õ��½T]kÛ0}߯pEhìâÙM7X‰çv%”v0֐µ{)Aå:6S$!ÉMJèߕ?R÷!>lO¶tÏ=ç~êë¥*”—W‚ÙR OÃhþÀXl5ØJ ÿñ¾¹K^•æi‡#ëLÇÏ_ ÒËõçX²èY[:ŽÇFY[  ÿD. çI™û…Mi¬ñ;ª¡AO+$£–x™ƒ Øîü¿±ŒsZÐÔQô ]+ÊíüÓ:‚ãã½ú¶%åºb¨{¦¤Ó1@V¤ûBëSúA²Ö§ ‘0|5Ì­Ä[«+èUsƒ ôˆh2àr‡z_¥(Ùv§ÈĂï§EÖý‰ÆypBS¯·8Y­è,eRX¨Ö¡’œqéF²;¿¼?Ø?Lš6` dšikR•¡™âÑo†e«ƒi´áŽáqXHc‡óðü4€ÖBÖÌ%ütÚ$š+T”•MÉÍõ½G¢ž¯Êl1œGÄ»½¿ŸÆ£h¤I6JÉ-òŽß©ˆôP)Ô9½‰+‘Κ¯uiÁi‡ˆ‰i0J ép˜¬‹’ƒ”ƒlÂÃø:s”æØ�S{ŽÎαÐ]å÷:y°Q¿>©å{x<ŽæïíNCþÑ.Mf?¨«2ý}=ûõýî'=£§ÿu•Ü(—¾IIa­"éþ@¶�¿ä9?^-qìÇÞôvŠeÈc ðlacã®xèÄ'®âd¶ çˆSEæódP/ÍÆv{Ô)Ó ?>…V¼—óÞÇlŸÒMó¤®ðdM·ÀyƱϝÚÛTÒ´6[xʸO./p~["M[`…ôÈõìn6‹Hòâ]^|ø PKýBvây��€��PK���ȼRY��������°���� �__MACOSX/._v3.phpUT �øŽg‰gþ“gux �õ��õ��c`cg`b`ðMLVðVˆP€'qƒøˆŽ!!AP&HÇ %PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (���d�o�m�p�d�f� �2�.�0�.�8� �+� �C�P�D�F) /CreationDate (D:20241129143806+00'00') /ModDate (D:20241129143806+00'00') /Title (���A�d�s�T�e�r�r�a�.�c�o�m� �i�n�v�o�i�c�e) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 904 >> stream x���]o�J���+F�ͩ����su\ �08=ʩzရ���lS��lc� "Ց� ���wޙ�%�R�DS��� �OI�a`� �Q�f��5����_���םO�`�7�_FA���D�Џ.j�a=�j����>��n���R+�P��l�rH�{0��w��0��=W�2D ����G���I�>�_B3ed�H�yJ�G>/��ywy�fk��%�$�2.��d_�h����&)b0��"[\B��*_.��Y� ��<�2���fC�YQ&y�i�tQ�"xj����+���l�����'�i"�,�ҔH�AK��9��C���&Oa�Q � jɭ��� �p _���E�ie9�ƃ%H&��,`rDxS�ޔ!�(�X!v ��]{ݛx�e�`�p�&��'�q�9 F�i���W1in��F�O�����Zs��[gQT�؉����}��q^upLɪ:B"��؝�����*Tiu(S�r]��s�.��s9n�N!K!L�M�?�*[��N�8��c��ۯ�b�� ��� �YZ���SR3�n�����lPN��P�;��^�]�!'�z-���ӊ���/��껣��4�l(M�E�QL��X ��~���G��M|�����*��~�;/=N4�-|y�`�i�\�e�T�<���L��G}�"В�J^���q��"X�?(V�ߣXۆ{��H[����P�� �c���kc�Z�9v�����? �a��R�h|��^�k�D4W���?Iӊ�]<��4�)$wdat���~�����������|�L��x�p|N�*��E� �/4�Qpi�x.>��d����,M�y|4^�Ż��8S/޾���uQe���D�y� ��ͧH�����j�wX � �&z� endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >> endobj xref 0 10 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000284 00000 n 0000000313 00000 n 0000000514 00000 n 0000000617 00000 n 0000001593 00000 n 0000001700 00000 n trailer << /Size 10 /Root 1 0 R /Info 5 0 R /ID[] >> startxref 1812 %%EOF
Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 128

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 129

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 131
//go:build go1.7 // +build go1.7 package expression import ( "reflect" "strings" "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/dynamodb" ) type exprErrorMode string const ( noExpressionError exprErrorMode = "" // invalidEscChar error will occer if the escape char '$' is either followed // by an unsupported character or if the escape char is the last character invalidEscChar = "invalid escape" // outOfRange error will occur if there are more escaped chars than there are // actual values to be aliased. outOfRange = "out of range" // invalidBuilderOperand error will occur if an invalid operand is used // as input for Build() invalidExpressionBuildOperand = "BuildOperand error" // unsetBuilder error will occur if Build() is called on an unset Builder unsetBuilder = "unset parameter: Builder" // unsetConditionBuilder error will occur if an unset ConditionBuilder is // used in WithCondition() unsetConditionBuilder = "unset parameter: ConditionBuilder" ) func TestBuild(t *testing.T) { cases := []struct { name string input Builder expected Expression err exprErrorMode }{ { name: "condition", input: NewBuilder().WithCondition(Name("foo").Equal(Value(5))), expected: Expression{ expressionMap: map[expressionType]string{ condition: "#0 = :0", }, namesMap: map[string]*string{ "#0": aws.String("foo"), }, valuesMap: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, }, }, { name: "projection", input: NewBuilder().WithProjection(NamesList(Name("foo"), Name("bar"), Name("baz"))), expected: Expression{ expressionMap: map[expressionType]string{ projection: "#0, #1, #2", }, namesMap: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), "#2": aws.String("baz"), }, }, }, { name: "keyCondition", input: NewBuilder().WithKeyCondition(Key("foo").Equal(Value(5))), expected: Expression{ expressionMap: map[expressionType]string{ keyCondition: "#0 = :0", }, namesMap: map[string]*string{ "#0": aws.String("foo"), }, valuesMap: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, }, }, { name: "filter", input: NewBuilder().WithFilter(Name("foo").Equal(Value(5))), expected: Expression{ expressionMap: map[expressionType]string{ filter: "#0 = :0", }, namesMap: map[string]*string{ "#0": aws.String("foo"), }, valuesMap: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, }, }, { name: "update", input: NewBuilder().WithUpdate(Set(Name("foo"), (Value(5)))), expected: Expression{ expressionMap: map[expressionType]string{ update: "SET #0 = :0\n", }, namesMap: map[string]*string{ "#0": aws.String("foo"), }, valuesMap: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, }, }, { name: "compound", input: NewBuilder(). WithCondition(Name("foo").Equal(Value(5))). WithFilter(Name("bar").LessThan(Value(6))). WithProjection(NamesList(Name("foo"), Name("bar"), Name("baz"))). WithKeyCondition(Key("foo").Equal(Value(5))). WithUpdate(Set(Name("foo"), Value(5))), expected: Expression{ expressionMap: map[expressionType]string{ condition: "#0 = :0", filter: "#1 < :1", projection: "#0, #1, #2", keyCondition: "#0 = :2", update: "SET #0 = :3\n", }, namesMap: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), "#2": aws.String("baz"), }, valuesMap: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, ":1": { N: aws.String("6"), }, ":2": { N: aws.String("5"), }, ":3": { N: aws.String("5"), }, }, }, }, { name: "invalid Builder", input: NewBuilder().WithCondition(Name("").Equal(Value(5))), err: invalidExpressionBuildOperand, }, { name: "unset Builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { actual, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } } }) } } func TestCondition(t *testing.T) { cases := []struct { name string input Builder expected *string err exprErrorMode }{ { name: "condition", input: Builder{ expressionMap: map[expressionType]treeBuilder{ condition: Name("foo").Equal(Value(5)), }, }, expected: aws.String("#0 = :0"), }, { name: "unset builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Condition() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestFilter(t *testing.T) { cases := []struct { name string input Builder expected *string err exprErrorMode }{ { name: "filter", input: Builder{ expressionMap: map[expressionType]treeBuilder{ filter: Name("foo").Equal(Value(5)), }, }, expected: aws.String("#0 = :0"), }, { name: "unset builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Filter() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestProjection(t *testing.T) { cases := []struct { name string input Builder expected *string err exprErrorMode }{ { name: "projection", input: Builder{ expressionMap: map[expressionType]treeBuilder{ projection: NamesList(Name("foo"), Name("bar"), Name("baz")), }, }, expected: aws.String("#0, #1, #2"), }, { name: "unset builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Projection() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestKeyCondition(t *testing.T) { cases := []struct { name string input Builder expected *string err exprErrorMode }{ { name: "keyCondition", input: Builder{ expressionMap: map[expressionType]treeBuilder{ keyCondition: KeyConditionBuilder{ operandList: []OperandBuilder{ KeyBuilder{ key: "foo", }, ValueBuilder{ value: 5, }, }, mode: equalKeyCond, }, }, }, expected: aws.String("#0 = :0"), }, { name: "empty builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.KeyCondition() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestUpdate(t *testing.T) { cases := []struct { name string input Builder expected *string err exprErrorMode }{ { name: "update", input: Builder{ expressionMap: map[expressionType]treeBuilder{ update: UpdateBuilder{ operationList: map[operationMode][]operationBuilder{ setOperation: { { name: NameBuilder{ name: "foo", }, value: ValueBuilder{ value: 5, }, mode: setOperation, }, }, }, }, }, }, expected: aws.String("SET #0 = :0\n"), }, { name: "multiple sets", input: Builder{ expressionMap: map[expressionType]treeBuilder{ update: UpdateBuilder{ operationList: map[operationMode][]operationBuilder{ setOperation: { { name: NameBuilder{ name: "foo", }, value: ValueBuilder{ value: 5, }, mode: setOperation, }, { name: NameBuilder{ name: "bar", }, value: ValueBuilder{ value: 6, }, mode: setOperation, }, { name: NameBuilder{ name: "baz", }, value: ValueBuilder{ value: 7, }, mode: setOperation, }, }, }, }, }, }, expected: aws.String("SET #0 = :0, #1 = :1, #2 = :2\n"), }, { name: "unset builder", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Update() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestNames(t *testing.T) { cases := []struct { name string input Builder expected map[string]*string err exprErrorMode }{ { name: "projection", input: Builder{ expressionMap: map[expressionType]treeBuilder{ projection: NamesList(Name("foo"), Name("bar"), Name("baz")), }, }, expected: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), "#2": aws.String("baz"), }, }, { name: "aggregate", input: Builder{ expressionMap: map[expressionType]treeBuilder{ condition: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "foo", }, ValueBuilder{ value: 5, }, }, mode: equalCond, }, filter: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "bar", }, ValueBuilder{ value: 6, }, }, mode: lessThanCond, }, projection: ProjectionBuilder{ names: []NameBuilder{ { name: "foo", }, { name: "bar", }, { name: "baz", }, }, }, }, }, expected: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), "#2": aws.String("baz"), }, }, { name: "unset", input: Builder{}, err: unsetBuilder, }, { name: "unset ConditionBuilder", input: NewBuilder().WithCondition(ConditionBuilder{}), err: unsetConditionBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Names() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestValues(t *testing.T) { cases := []struct { name string input Builder expected map[string]*dynamodb.AttributeValue err exprErrorMode }{ { name: "empty lists become null", input: Builder{ expressionMap: map[expressionType]treeBuilder{ update: Name("groups").Equal(Value([]string{})), }, }, expected: map[string]*dynamodb.AttributeValue{ ":0": { NULL: aws.Bool(true), }, }, }, { name: "dynamodb.AttributeValue values are used directly", input: Builder{ expressionMap: map[expressionType]treeBuilder{ update: Name("key").Equal(Value(dynamodb.AttributeValue{ S: aws.String("value"), })), }, }, expected: map[string]*dynamodb.AttributeValue{ ":0": { S: aws.String("value"), }, }, }, { name: "condition", input: Builder{ expressionMap: map[expressionType]treeBuilder{ condition: Name("foo").Equal(Value(5)), }, }, expected: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, }, { name: "aggregate", input: Builder{ expressionMap: map[expressionType]treeBuilder{ condition: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "foo", }, ValueBuilder{ value: 5, }, }, mode: equalCond, }, filter: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "bar", }, ValueBuilder{ value: 6, }, }, mode: lessThanCond, }, projection: ProjectionBuilder{ names: []NameBuilder{ { name: "foo", }, { name: "bar", }, { name: "baz", }, }, }, }, }, expected: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, ":1": { N: aws.String("6"), }, }, }, { name: "unset", input: Builder{}, err: unsetBuilder, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.Build() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } actual := expr.Values() if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestBuildChildTrees(t *testing.T) { cases := []struct { name string input Builder expectedaliasList aliasList expectedStringMap map[expressionType]string err exprErrorMode }{ { name: "aggregate", input: Builder{ expressionMap: map[expressionType]treeBuilder{ condition: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "foo", }, ValueBuilder{ value: 5, }, }, mode: equalCond, }, filter: ConditionBuilder{ operandList: []OperandBuilder{ NameBuilder{ name: "bar", }, ValueBuilder{ value: 6, }, }, mode: lessThanCond, }, projection: ProjectionBuilder{ names: []NameBuilder{ { name: "foo", }, { name: "bar", }, { name: "baz", }, }, }, }, }, expectedaliasList: aliasList{ namesList: []string{"foo", "bar", "baz"}, valuesList: []dynamodb.AttributeValue{ { N: aws.String("5"), }, { N: aws.String("6"), }, }, }, expectedStringMap: map[expressionType]string{ condition: "#0 = :0", filter: "#1 < :1", projection: "#0, #1, #2", }, }, { name: "unset", input: Builder{}, expectedaliasList: aliasList{}, expectedStringMap: map[expressionType]string{}, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { actualAL, actualSM, err := c.input.buildChildTrees() if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } } if e, a := c.expectedaliasList, actualAL; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } if e, a := c.expectedStringMap, actualSM; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestBuildExpressionString(t *testing.T) { cases := []struct { name string input exprNode expectedNames map[string]*string expectedValues map[string]*dynamodb.AttributeValue expectedExpression string err exprErrorMode }{ { name: "basic name", input: exprNode{ names: []string{"foo"}, fmtExpr: "$n", }, expectedValues: map[string]*dynamodb.AttributeValue{}, expectedNames: map[string]*string{ "#0": aws.String("foo"), }, expectedExpression: "#0", }, { name: "basic value", input: exprNode{ values: []dynamodb.AttributeValue{ { N: aws.String("5"), }, }, fmtExpr: "$v", }, expectedNames: map[string]*string{}, expectedValues: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, expectedExpression: ":0", }, { name: "nested path", input: exprNode{ names: []string{"foo", "bar"}, fmtExpr: "$n.$n", }, expectedValues: map[string]*dynamodb.AttributeValue{}, expectedNames: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), }, expectedExpression: "#0.#1", }, { name: "nested path with index", input: exprNode{ names: []string{"foo", "bar", "baz"}, fmtExpr: "$n.$n[0].$n", }, expectedValues: map[string]*dynamodb.AttributeValue{}, expectedNames: map[string]*string{ "#0": aws.String("foo"), "#1": aws.String("bar"), "#2": aws.String("baz"), }, expectedExpression: "#0.#1[0].#2", }, { name: "basic size", input: exprNode{ names: []string{"foo"}, fmtExpr: "size ($n)", }, expectedValues: map[string]*dynamodb.AttributeValue{}, expectedNames: map[string]*string{ "#0": aws.String("foo"), }, expectedExpression: "size (#0)", }, { name: "duplicate path name", input: exprNode{ names: []string{"foo", "foo"}, fmtExpr: "$n.$n", }, expectedValues: map[string]*dynamodb.AttributeValue{}, expectedNames: map[string]*string{ "#0": aws.String("foo"), }, expectedExpression: "#0.#0", }, { name: "equal expression", input: exprNode{ children: []exprNode{ { names: []string{"foo"}, fmtExpr: "$n", }, { values: []dynamodb.AttributeValue{ { N: aws.String("5"), }, }, fmtExpr: "$v", }, }, fmtExpr: "$c = $c", }, expectedNames: map[string]*string{ "#0": aws.String("foo"), }, expectedValues: map[string]*dynamodb.AttributeValue{ ":0": { N: aws.String("5"), }, }, expectedExpression: "#0 = :0", }, { name: "missing char after $", input: exprNode{ names: []string{"foo", "foo"}, fmtExpr: "$n.$", }, err: invalidEscChar, }, { name: "names out of range", input: exprNode{ names: []string{"foo"}, fmtExpr: "$n.$n", }, err: outOfRange, }, { name: "values out of range", input: exprNode{ fmtExpr: "$v", }, err: outOfRange, }, { name: "children out of range", input: exprNode{ fmtExpr: "$c", }, err: outOfRange, }, { name: "invalid escape char", input: exprNode{ fmtExpr: "$!", }, err: invalidEscChar, }, { name: "unset exprNode", input: exprNode{}, expectedExpression: "", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { expr, err := c.input.buildExpressionString(&aliasList{}) if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } if e, a := c.expectedExpression, expr; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } } }) } } func TestReturnExpression(t *testing.T) { cases := []struct { name string input Expression expected *string }{ { name: "projection exists", input: Expression{ expressionMap: map[expressionType]string{ projection: "#0, #1, #2", }, }, expected: aws.String("#0, #1, #2"), }, { name: "projection not exists", input: Expression{ expressionMap: map[expressionType]string{}, }, expected: nil, }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { actual := c.input.returnExpression(projection) if e, a := c.expected, actual; !reflect.DeepEqual(a, e) { t.Errorf("expect %v, got %v", e, a) } }) } } func TestAliasValue(t *testing.T) { cases := []struct { name string input *aliasList expected string err exprErrorMode }{ { name: "first item", input: &aliasList{}, expected: ":0", }, { name: "fifth item", input: &aliasList{ valuesList: []dynamodb.AttributeValue{ {}, {}, {}, {}, }, }, expected: ":4", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { str, err := c.input.aliasValue(dynamodb.AttributeValue{}) if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } if e, a := c.expected, str; e != a { t.Errorf("expect %v, got %v", e, a) } } }) } } func TestAliasPath(t *testing.T) { cases := []struct { name string inputList *aliasList inputName string expected string err exprErrorMode }{ { name: "new unique item", inputList: &aliasList{}, inputName: "foo", expected: "#0", }, { name: "duplicate item", inputList: &aliasList{ namesList: []string{ "foo", "bar", }, }, inputName: "foo", expected: "#0", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { str, err := c.inputList.aliasPath(c.inputName) if c.err != noExpressionError { if err == nil { t.Errorf("expect error %q, got no error", c.err) } else { if e, a := string(c.err), err.Error(); !strings.Contains(a, e) { t.Errorf("expect %q error message to be in %q", e, a) } } } else { if err != nil { t.Errorf("expect no error, got unexpected Error %q", err) } if e, a := c.expected, str; e != a { t.Errorf("expect %v, got %v", e, a) } } }) } }