-
Notifications
You must be signed in to change notification settings - Fork 192
Added new properties to Test proto #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fernst
wants to merge
1
commit into
main
Choose a base branch
from
add-extra-unittest-properties
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,176 @@ | ||
| import { suite } from "df/testing"; | ||
| // tslint:disable tsr-detect-non-literal-fs-filename | ||
| import { expect } from "chai"; | ||
| import * as fs from "fs-extra"; | ||
| import * as path from "path"; | ||
|
|
||
| suite("test", () => { | ||
| // This action currently has no unit tests! | ||
| import { asPlainObject, suite, test } from "df/testing"; | ||
| import { TmpDirFixture } from "df/testing/fixtures"; | ||
| import { | ||
| coreExecutionRequestFromPath, | ||
| runMainInVm, | ||
| VALID_WORKFLOW_SETTINGS_YAML | ||
| } from "df/testing/run_core"; | ||
|
|
||
| suite("test", ({ afterEach }) => { | ||
| const tmpDirFixture = new TmpDirFixture(afterEach); | ||
|
|
||
| test(`test with no inputs`, () => { | ||
| const projectDir = tmpDirFixture.createNewTmpDir(); | ||
| const workflowSettingsPath = path.join(projectDir, "workflow_settings.yaml"); | ||
| const definitionsDir = path.join(projectDir, "definitions"); | ||
| const actionsYamlPath = path.join(definitionsDir, "actions.yaml"); | ||
| const actionSqlPath = path.join(definitionsDir, "action.sql"); | ||
| const actionTestSqlxPath = path.join(definitionsDir, "action_test.sqlx"); | ||
|
|
||
| fs.writeFileSync(workflowSettingsPath, VALID_WORKFLOW_SETTINGS_YAML); | ||
| fs.mkdirSync(definitionsDir); | ||
| fs.writeFileSync(actionsYamlPath, ` | ||
| actions: | ||
| - table: | ||
| filename: action.sql` | ||
| ); | ||
| fs.writeFileSync(actionSqlPath, "SELECT 1"); | ||
| fs.writeFileSync(actionTestSqlxPath, ` | ||
| config { | ||
| type: "test", | ||
| dataset: "action" | ||
| } | ||
| SELECT 1`); | ||
|
|
||
| const result = runMainInVm(coreExecutionRequestFromPath(projectDir)); | ||
|
|
||
| expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]); | ||
| expect(asPlainObject(result.compile.compiledGraph.tests)).deep.equals( | ||
| asPlainObject([ | ||
| { | ||
| // Original test properties | ||
| name: "action_test", | ||
| testQuery: "SELECT 1", | ||
| expectedOutputQuery: "\n\nSELECT 1", | ||
| fileName: "definitions/action_test.sqlx", | ||
|
|
||
| // New properties | ||
| testTarget: { | ||
| database: "defaultProject", | ||
| schema: "defaultDataset", | ||
| name: "action" | ||
| }, | ||
| query: "SELECT 1", | ||
| resolveSchema: false, | ||
| } | ||
| ]) | ||
| ); | ||
| }); | ||
|
|
||
| test(`test with multiple_inputs input`, () => { | ||
| const projectDir = tmpDirFixture.createNewTmpDir(); | ||
| const workflowSettingsPath = path.join(projectDir, "workflow_settings.yaml"); | ||
| const definitionsDir = path.join(projectDir, "definitions"); | ||
| const actionsYamlPath = path.join(definitionsDir, "actions.yaml"); | ||
| const action1SqlxPath = path.join(definitionsDir, "action1.sqlx"); | ||
| const action1TestSqlxPath = path.join(definitionsDir, "action1_test.sqlx"); | ||
| const action2SqlxPath = path.join(definitionsDir, "action2.sqlx"); | ||
| const action2TestSqlxPath = path.join(definitionsDir, "action2_test.sqlx"); | ||
|
|
||
| fs.writeFileSync(workflowSettingsPath, VALID_WORKFLOW_SETTINGS_YAML); | ||
| fs.mkdirSync(definitionsDir); | ||
|
|
||
| // Add a declaration | ||
| fs.writeFileSync(actionsYamlPath, ` | ||
| actions: | ||
| - declaration: | ||
| name: a_declaration` | ||
| ); | ||
|
|
||
| // Add an action with a test, reads from declaration | ||
| fs.writeFileSync(action1SqlxPath, ` | ||
| config { | ||
| type: "table", | ||
| } | ||
| SELECT a,b,c FROM \${ref("a_declaration")} | ||
| `); | ||
| fs.writeFileSync(action1TestSqlxPath, ` | ||
| config { | ||
| type: "test", | ||
| dataset: "action1" | ||
| } | ||
| input "a_declaration" { | ||
| SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS d | ||
| } | ||
| SELECT 1 AS a, 2 AS b, 3 AS c`); | ||
|
|
||
|
|
||
| // Add an action with a test, reads from previous action | ||
| fs.writeFileSync(action2SqlxPath, ` | ||
| config { | ||
| type: "table", | ||
| } | ||
| SELECT a,b FROM \${ref("action1")} | ||
| `); | ||
| fs.writeFileSync(action2TestSqlxPath, ` | ||
| config { | ||
| type: "test", | ||
| dataset: "action2" | ||
| } | ||
| input "action1" { | ||
| SELECT 1 AS a, 2 AS b, 3 AS c | ||
| } | ||
| SELECT 1 AS a, 2 AS b`); | ||
|
|
||
| const result = runMainInVm(coreExecutionRequestFromPath(projectDir)); | ||
|
|
||
| expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]); | ||
| expect(asPlainObject(result.compile.compiledGraph.tests)).deep.equals( | ||
| asPlainObject([ | ||
| { | ||
| // Original test properties | ||
| name: "action1_test", | ||
| testQuery: "\n\nSELECT a,b,c FROM (\n SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS d\n)\n ", | ||
| expectedOutputQuery: "\n\n\nSELECT 1 AS a, 2 AS b, 3 AS c", | ||
| fileName: "definitions/action1_test.sqlx", | ||
|
|
||
| // New properties | ||
| testTarget: { | ||
| database: "defaultProject", | ||
| schema: "defaultDataset", | ||
| name: "action1" | ||
| }, | ||
| inputs: [{ | ||
| query: "\n SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS d\n", | ||
| target: { | ||
| database: "defaultProject", | ||
| schema: "defaultDataset", | ||
| name: "a_declaration" | ||
| } | ||
| }], | ||
| query: "\n\nSELECT a,b,c FROM `defaultProject.defaultDataset.a_declaration`\n ", | ||
| resolveSchema: false, | ||
| }, | ||
| { | ||
| // Original test properties | ||
| name: "action2_test", | ||
| testQuery: "\n\nSELECT a,b FROM (\n SELECT 1 AS a, 2 AS b, 3 AS c\n)\n ", | ||
| expectedOutputQuery: "\n\n\nSELECT 1 AS a, 2 AS b", | ||
| fileName: "definitions/action2_test.sqlx", | ||
|
|
||
| // New properties | ||
| testTarget: { | ||
| database: "defaultProject", | ||
| schema: "defaultDataset", | ||
| name: "action2" | ||
| }, | ||
| inputs: [{ | ||
| query: "\n SELECT 1 AS a, 2 AS b, 3 AS c\n", | ||
| target: { | ||
| database: "defaultProject", | ||
| schema: "defaultDataset", | ||
| name: "action1" | ||
| } | ||
| }], | ||
| query: "\n\nSELECT a,b FROM `defaultProject.defaultDataset.action1`\n ", | ||
| resolveSchema: false, | ||
| } | ||
| ]) | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not ready to accept this proposal:
queryandinputsand oldtest_queryandexpected_output_query(I myself spend a lot of time to understand it)