Skip to content

Commit

Permalink
Restore ability to unit test views (#1824)
Browse files Browse the repository at this point in the history
* restore ability to unit test views

* apply suggested style changes

Co-authored-by: Elias Kassell <eliaskassell@gmail.com>

* apply suggested style change: newline

* fix bug introduced by style change

---------

Co-authored-by: Barna Magyarkuti <barna.magyarkuti@sap.com>
Co-authored-by: Elias Kassell <eliaskassell@gmail.com>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent b309aa0 commit 1f48a0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/actions/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StringifiedMap } from "df/common/strings/stringifier";
import { ActionBuilder } from "df/core/actions";
import * as table from "df/core/actions/table";
import { ITableContext } from "df/core/actions/table";
import { View } from "df/core/actions/view";
import { Contextable, ICommonContext, INamedConfig, Resolvable } from "df/core/common";
import { Session } from "df/core/session";
import { targetStringifier } from "df/core/targets";
Expand Down Expand Up @@ -107,7 +108,7 @@ export class Test extends ActionBuilder<dataform.Test> {
);
}
const dataset = allResolved.length > 0 ? allResolved[0] : undefined;
if (!(dataset && dataset instanceof table.Table)) {
if (!(dataset && (dataset instanceof table.Table || dataset instanceof View))) {
this.session.compileError(
new Error(`Dataset ${stringifyResolvable(this.datasetToTest)} could not be found.`),
this.proto.fileName
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/bigquery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ suite("@dataform/integration/bigquery", { parallel: true }, ({ before, after })
'For row 1 and column "col3": expected "6.5", but saw "12".',
'For row 2 and column "col1": expected "sup?", but saw "WRONG".'
]
}
},
{ name: "test a view", successful: true },
]);
});

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/bigquery_project/definitions/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ test("wrong row contents")
select 'sup?' as col3, 3 as col2, 9.5 as col3, true as col4
`
);

test("test a view")
.dataset("example_view")
.input(
"sample_data",
"select 'hi' as col1, 1 as col2, 3.5 as col3, true as col4, date '2020-07-23' as col5"
)
.expect(
"select 'hi' as col1, 1 as col2, 3.5 as col3, true as col4, date '2020-07-23' as col5"
);

0 comments on commit 1f48a0e

Please sign in to comment.