use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.
the class BaseQueryAssertionsTest method testReturnsEmptyResult.
@Test
public void testReturnsEmptyResult() {
assertThat(query("SELECT 'foobar' WHERE false")).returnsEmptyResult();
QueryAssert queryAssert = assertThat(query("VALUES 'foobar'"));
assertThatThrownBy(queryAssert::returnsEmptyResult).hasMessage("[Rows for query [VALUES 'foobar']] \nExpecting empty but was:<[[foobar]]>");
queryAssert = assertThat(query("VALUES 'foo', 'bar'"));
assertThatThrownBy(queryAssert::returnsEmptyResult).hasMessage("[Rows for query [VALUES 'foo', 'bar']] \nExpecting empty but was:<[[foo], [bar]]>");
}
use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.
the class BaseQueryAssertionsTest method testNestedVarbinaryResult.
@Test
public void testNestedVarbinaryResult() {
assertThat(query("SELECT CAST(ROW(X'001234') AS ROW(foo varbinary))")).matches("SELECT CAST(ROW(X'001234') AS ROW(foo varbinary))");
QueryAssert queryAssert = assertThat(query("SELECT CAST(ROW(X'001234') AS ROW(foo varbinary))"));
assertThatThrownBy(() -> queryAssert.matches("SELECT CAST(ROW(X'001299') AS ROW(foo varbinary))")).hasMessageMatching(// TODO the representation and thus messages should be the same regardless of query runner in use
getQueryRunner() instanceof LocalQueryRunner ? "(?s).*" + "\\Q" + "Expecting:\n" + " <([00 12 34])>\n" + "to contain exactly in any order:\n" + " <[([00 12 99])]>\n" + "elements not found:\n" + " <([00 12 99])>\n" + "and elements not expected:\n" + " <([00 12 34])>" + "\\E.*" : "(?s).*" + "\\Q" + "Expecting:\n" + " <([X'00 12 34'])>\n" + "to contain exactly in any order:\n" + " <[([X'00 12 99'])]>\n" + "elements not found:\n" + " <([X'00 12 99'])>\n" + "and elements not expected:\n" + " <([X'00 12 34'])>" + "\\E.*");
}
use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.
the class BaseQueryAssertionsTest method testTimestampWithTimeZoneQueryResult.
/**
* Tests query runner with results of various precisions, and query assert.
*/
@Test
public void testTimestampWithTimeZoneQueryResult() {
assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123 Europe/Warsaw'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123 Europe/Warsaw'");
assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456 Europe/Warsaw'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456 Europe/Warsaw'");
assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789 Europe/Warsaw'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789 Europe/Warsaw'");
assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Warsaw'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Warsaw'");
QueryAssert queryAssert = assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Warsaw'"));
// different second fraction
assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789013 Europe/Warsaw'")).hasMessageContaining("Expecting:\n" + " <(2017-01-02 09:12:34.123456789012 Europe/Warsaw)>\n" + "to contain exactly in any order:\n" + " <[(2017-01-02 09:12:34.123456789013 Europe/Warsaw)]>");
// different zone
assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Paris'")).hasMessageContaining("Expecting:\n" + " <(2017-01-02 09:12:34.123456789012 Europe/Warsaw)>\n" + "to contain exactly in any order:\n" + " <[(2017-01-02 09:12:34.123456789012 Europe/Paris)]>");
}
use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.
the class BaseQueryAssertionsTest method testWrongType.
@Test
public void testWrongType() {
QueryAssert queryAssert = assertThat(query("SELECT X'001234'"));
assertThatThrownBy(() -> queryAssert.matches("VALUES '001234'")).hasMessageContaining("[Output types for query [SELECT X'001234']] expected:<[var[char(6)]]> but was:<[var[binary]]>");
}
Aggregations