Search in sources :

Example 6 with QueryAssert

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]]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Example 7 with QueryAssert

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.*");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 8 with QueryAssert

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)]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Example 9 with QueryAssert

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]]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Aggregations

QueryAssert (io.trino.sql.query.QueryAssertions.QueryAssert)9 Test (org.testng.annotations.Test)8 Type (io.trino.spi.type.Type)1 QueryAssertions (io.trino.sql.query.QueryAssertions)1 LocalQueryRunner (io.trino.testing.LocalQueryRunner)1 MaterializedResult (io.trino.testing.MaterializedResult)1