Skip to content

Commit

Permalink
Add ts codec unit tests for blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmoore committed Nov 30, 2016
1 parent 2278151 commit 69010b7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/riak_pb_ts_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ decode_ts_range(#tsrange{field_name = FieldName,
encode_cells_test() ->
%% Correct cells
?assertEqual(#tscell{varchar_value = <<"Foo">>}, encode_cell({varchar, <<"Foo">>})),
?assertEqual(#tscell{varchar_value = <<0,1,2,3>>}, encode_cell({blob, <<0,1,2,3>>})),
?assertEqual(#tscell{sint64_value = 64}, encode_cell({sint64, 64})),
?assertEqual(#tscell{timestamp_value = 64}, encode_cell({timestamp, 64})),
?assertEqual(#tscell{boolean_value = true}, encode_cell({boolean, true})),
Expand All @@ -315,6 +316,7 @@ encode_cells_test() ->

%% Null Cells
?assertEqual(#tscell{}, encode_cell({varchar, []})),
?assertEqual(#tscell{}, encode_cell({blob, []})),
?assertEqual(#tscell{}, encode_cell({sint64, []})),
?assertEqual(#tscell{}, encode_cell({timestamp, []})),
?assertEqual(#tscell{}, encode_cell({boolean, []})),
Expand All @@ -332,18 +334,19 @@ encode_row_test() ->
?assertEqual(
#tsrow{cells = [
#tscell{varchar_value = <<"Foo">>},
#tscell{varchar_value = <<0,1,2,3>>},
#tscell{sint64_value = 64},
#tscell{timestamp_value = 42},
#tscell{boolean_value = false},
#tscell{double_value = 42.2},
#tscell{}
]},
encode_row(
[varchar, sint64, timestamp, boolean, double, varchar],
[<<"Foo">>, 64, 42, false, 42.2, []]
[varchar, blob, sint64, timestamp, boolean, double, varchar],
[<<"Foo">>, <<0,1,2,3>>, 64, 42, false, 42.2, []]
)),
?assertError(function_clause, encode_row([], [<<"Foo">>, 64, 42, false, 42.2, []])),
?assertError(function_clause, encode_row([varchar, sint64, timestamp], [<<"Foo">>, 64, 42, false, 42.2, []])).
?assertError(function_clause, encode_row([], [<<"Foo">>, <<0,1,2,3>>, 64, 42, false, 42.2, []])),
?assertError(function_clause, encode_row([varchar, sint64, timestamp], [<<"Foo">>, <<0,1,2,3>>, 64, 42, false, 42.2, []])).

encode_rows_test() ->
?assertEqual(
Expand All @@ -364,13 +367,15 @@ encode_rows_test() ->

encode_field_type_test() ->
?assertEqual('VARCHAR', encode_field_type(varchar)),
?assertEqual('BLOB', encode_field_type(blob)),
?assertEqual('SINT64',encode_field_type(sint64)),
?assertEqual('TIMESTAMP',encode_field_type(timestamp)),
?assertEqual('BOOLEAN',encode_field_type(boolean)),
?assertEqual('DOUBLE',encode_field_type(double)).

decode_cell_test() ->
?assertEqual([<<"Foo">>], decode_cells([#tscell{varchar_value = <<"Foo">>}],[])),
?assertEqual([<<0,1,2,3>>], decode_cells([#tscell{varchar_value = <<0,1,2,3>>}],[])),
?assertEqual([42], decode_cells([#tscell{sint64_value = 42}],[])),
?assertEqual([64], decode_cells([#tscell{timestamp_value = 64}],[])),
?assertEqual([false], decode_cells([#tscell{boolean_value = false}],[])),
Expand Down

0 comments on commit 69010b7

Please sign in to comment.