Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit f351057

Browse files
authored
feat: added DataType integration test for arrays (#1100)
Part of #1096
1 parent 9876b58 commit f351057

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

google/cloud/spanner/integration_tests/data_types_integration_test.cc

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,93 @@ TEST_F(DataTypeIntegrationTest, WriteReadDate) {
208208
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
209209
}
210210

211+
TEST_F(DataTypeIntegrationTest, WriteReadArrayBool) {
212+
std::vector<std::vector<bool>> const data = {
213+
std::vector<bool>{},
214+
std::vector<bool>{true},
215+
std::vector<bool>{false},
216+
std::vector<bool>{true, false},
217+
std::vector<bool>{false, true},
218+
};
219+
auto result = WriteReadData(*client_, data, "ArrayBoolValue");
220+
ASSERT_STATUS_OK(result);
221+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
222+
}
223+
224+
TEST_F(DataTypeIntegrationTest, WriteReadArrayInt64) {
225+
std::vector<std::vector<std::int64_t>> const data = {
226+
std::vector<std::int64_t>{},
227+
std::vector<std::int64_t>{-1},
228+
std::vector<std::int64_t>{-1, 0, 1},
229+
};
230+
auto result = WriteReadData(*client_, data, "ArrayInt64Value");
231+
ASSERT_STATUS_OK(result);
232+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
233+
}
234+
235+
TEST_F(DataTypeIntegrationTest, WriteReadArrayFloat64) {
236+
std::vector<std::vector<double>> const data = {
237+
std::vector<double>{},
238+
std::vector<double>{-0.5},
239+
std::vector<double>{-0.5, 0.5, 1.5},
240+
};
241+
auto result = WriteReadData(*client_, data, "ArrayFloat64Value");
242+
ASSERT_STATUS_OK(result);
243+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
244+
}
245+
246+
TEST_F(DataTypeIntegrationTest, WriteReadArrayString) {
247+
std::vector<std::vector<std::string>> const data = {
248+
std::vector<std::string>{},
249+
std::vector<std::string>{""},
250+
std::vector<std::string>{"", "foo", "bar"},
251+
};
252+
auto result = WriteReadData(*client_, data, "ArrayStringValue");
253+
ASSERT_STATUS_OK(result);
254+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
255+
}
256+
257+
TEST_F(DataTypeIntegrationTest, WriteReadArrayBytes) {
258+
std::vector<std::vector<Bytes>> const data = {
259+
std::vector<Bytes>{},
260+
std::vector<Bytes>{Bytes("")},
261+
std::vector<Bytes>{Bytes(""), Bytes("foo"), Bytes("bar")},
262+
};
263+
auto result = WriteReadData(*client_, data, "ArrayBytesValue");
264+
ASSERT_STATUS_OK(result);
265+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
266+
}
267+
268+
TEST_F(DataTypeIntegrationTest, WriteReadArrayTimestamp) {
269+
std::vector<std::vector<Timestamp>> const data = {
270+
std::vector<Timestamp>{},
271+
std::vector<Timestamp>{Timestamp(std::chrono::seconds(-1))},
272+
std::vector<Timestamp>{
273+
Timestamp(std::chrono::seconds(-1)),
274+
Timestamp(),
275+
Timestamp(std::chrono::seconds(1)),
276+
},
277+
};
278+
auto result = WriteReadData(*client_, data, "ArrayTimestampValue");
279+
ASSERT_STATUS_OK(result);
280+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
281+
}
282+
283+
TEST_F(DataTypeIntegrationTest, WriteReadArrayDate) {
284+
std::vector<std::vector<Date>> const data = {
285+
std::vector<Date>{},
286+
std::vector<Date>{Date()},
287+
std::vector<Date>{
288+
Date(1, 1, 1),
289+
Date(),
290+
Date(9999, 12, 31),
291+
},
292+
};
293+
auto result = WriteReadData(*client_, data, "ArrayDateValue");
294+
ASSERT_STATUS_OK(result);
295+
EXPECT_THAT(*result, UnorderedElementsAreArray(data));
296+
}
297+
211298
} // namespace
212299
} // namespace SPANNER_CLIENT_NS
213300
} // namespace spanner

google/cloud/spanner/testing/database_environment.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ void DatabaseEnvironment::SetUp() {
5757
StringValue STRING(1024),
5858
BytesValue BYTES(1024),
5959
TimestampValue TIMESTAMP,
60-
DateValue DATE
60+
DateValue DATE,
61+
ArrayBoolValue ARRAY<BOOL>,
62+
ArrayInt64Value ARRAY<INT64>,
63+
ArrayFloat64Value ARRAY<FLOAT64>,
64+
ArrayStringValue ARRAY<STRING(1024)>,
65+
ArrayBytesValue ARRAY<BYTES(1024)>,
66+
ArrayTimestampValue ARRAY<TIMESTAMP>,
67+
ArrayDateValue ARRAY<DATE>
6168
) PRIMARY KEY (Id))sql"});
6269
int i = 0;
6370
int const timeout = 120;

0 commit comments

Comments
 (0)