Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
320 changes: 106 additions & 214 deletions cli/index_compile_test.ts

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions cli/index_help_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { expect } from "chai";
import { execFile } from "child_process";

import { cliEntryPointPath } from "df/cli/index_test_base";
import { getProcessResult, nodePath, suite, test } from "df/testing";
import { runCli } from "df/cli/index_test_base";
import { suite, test } from "df/testing";

suite("help command", () => {
test("shows global help with the help command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help"]));
const result = await runCli("help");
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("dataform [command]");
Expand All @@ -20,7 +19,7 @@ suite("help command", () => {
});

test("shows help for 'init' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "init"]));
const result = await runCli("help", ["init"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Create a new dataform project.");
Expand All @@ -29,15 +28,15 @@ suite("help command", () => {
});

test("shows help for 'install' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "install"]));
const result = await runCli("help", ["install"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Install a project's NPM dependencies.");
expect(output).to.include("[project-dir]");
});

test("shows help for 'init-creds' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "init-creds"]));
const result = await runCli("help", ["init-creds"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Create a .df-credentials.json file for Dataform to use when accessing BigQuery.");
Expand All @@ -47,7 +46,7 @@ suite("help command", () => {
});

test("shows help for 'compile' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "compile"]));
const result = await runCli("help", ["compile"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Compile the dataform project.");
Expand All @@ -57,7 +56,7 @@ suite("help command", () => {
});

test("shows help for 'test' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "test"]));
const result = await runCli("help", ["test"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Run the dataform project's unit tests.");
Expand All @@ -69,7 +68,7 @@ suite("help command", () => {
});

test("shows help for 'run' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "run"]));
const result = await runCli("help", ["run"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Run the dataform project.");
Expand All @@ -84,8 +83,8 @@ suite("help command", () => {
expect(output).to.include("--job-labels");
});

test("shows help for 'format' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "format"]));
test("shows help for 'format' command", async () => {
const result = await runCli("help", ["format"]);
expect(result.exitCode).equals(0);
const output = result.stdout;
expect(output).to.include("Format the dataform project's files.");
Expand Down
83 changes: 38 additions & 45 deletions cli/index_init_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { assert, expect } from "chai";
import { execFile } from "child_process";
import * as fs from "fs-extra";
import { load as loadYaml } from "js-yaml";
import * as path from "path";

import { cliEntryPointPath } from "df/cli/index_test_base";
import { runCli } from "df/cli/index_test_base";
import {
ICEBERG_BUCKET_NAME_HINT,
ICEBERG_BUCKET_NAME_PROMPT_QUESTION,
Expand All @@ -20,7 +19,7 @@ import {
} from "df/cli/util";
import { version } from "df/core/version";
import { dataform } from "df/protos/ts";
import { getProcessResult, nodePath, suite, test } from "df/testing";
import { suite, test } from "df/testing";
import { TmpDirFixture } from "df/testing/fixtures";

suite("init command", ({ afterEach }) => {
Expand All @@ -29,15 +28,11 @@ suite("init command", ({ afterEach }) => {
test("workflow_settings.yaml generated from init", async () => {
const projectDir = tmpDirFixture.createNewTmpDir();

await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
projectDir,
"--default-database=dataform-database",
"--default-location=us-central1"
])
);
await runCli("init", [
projectDir,
"--default-database=dataform-database",
"--default-location=us-central1"
]);

expect(fs.readFileSync(path.join(projectDir, "workflow_settings.yaml"), "utf8")).to
.equal(`dataformCoreVersion: ${version}
Expand All @@ -58,18 +53,18 @@ defaultAssertionDataset: dataform_assertions
[ICEBERG_CONNECTION_QUESTION]: "my.default.connection",
};

const result = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
const result = await runCli(
"init",
[
projectDir,
"dataform-iceberg-test",
"us-central1",
"--iceberg"
], {
],
{
// Inject test inputs via environment variable
env: { ...process.env, DATAFORM_CLI_TEST_INPUTS: JSON.stringify(testInputs) }
})
}
);

expect(result.exitCode).equals(0);
Expand Down Expand Up @@ -100,18 +95,18 @@ defaultAssertionDataset: dataform_assertions
[ICEBERG_CONNECTION_QUESTION]: "my.default.connection",
};

const result = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
const result = await runCli(
"init",
[
projectDir,
"dataform-iceberg-partial",
"us-east1",
"--iceberg"
], {
],
{
// Inject test inputs via environment variable
env: { ...process.env, DATAFORM_CLI_TEST_INPUTS: JSON.stringify(testInputs) }
})
}
);

expect(result.exitCode).equals(0);
Expand Down Expand Up @@ -146,18 +141,18 @@ defaultAssertionDataset: dataform_assertions
[ICEBERG_CONNECTION_QUESTION]: "my.default.connection",
};

const result = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
const result = await runCli(
"init",
[
projectDir,
"dataform-iceberg-partial",
"us-east1",
"--iceberg"
], {
],
{
// Inject test inputs via environment variable
env: { ...process.env, DATAFORM_CLI_TEST_INPUTS: JSON.stringify(testInputs) }
})
}
);

expect(result.exitCode).equals(0);
Expand Down Expand Up @@ -192,18 +187,18 @@ defaultAssertionDataset: dataform_assertions
[ICEBERG_CONNECTION_QUESTION]: "my.default.connection",
};

const result = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
const result = await runCli(
"init",
[
projectDir,
"dataform-iceberg-partial",
"us-east1",
"--iceberg"
], {
],
{
// Inject test inputs via environment variable
env: { ...process.env, DATAFORM_CLI_TEST_INPUTS: JSON.stringify(testInputs) }
})
}
);

expect(result.exitCode).equals(0);
Expand Down Expand Up @@ -238,18 +233,18 @@ defaultAssertionDataset: dataform_assertions
[ICEBERG_CONNECTION_QUESTION]: "", // Empty input
};

const result = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
const result = await runCli(
"init",
[
projectDir,
"dataform-iceberg-partial",
"us-east1",
"--iceberg"
], {
],
{
// Inject test inputs via environment variable
env: { ...process.env, DATAFORM_CLI_TEST_INPUTS: JSON.stringify(testInputs) }
})
}
);

expect(result.exitCode).equals(0);
Expand Down Expand Up @@ -282,9 +277,7 @@ suite("init-creds command", ({ afterEach }) => {

test("init-creds fails for directory without dataform config", async () => {
const emptyDir = tmpDirFixture.createNewTmpDir();
const result = await getProcessResult(
execFile(nodePath, [cliEntryPointPath, "init-creds", emptyDir])
);
const result = await runCli("init-creds", [emptyDir]);
expect(result.exitCode).to.not.equal(0);
expect(result.stderr).to.include(
`${emptyDir} does not appear to be a dataform directory (missing workflow_settings.yaml file).`
Expand Down
Loading
Loading