|
1 | 1 | // tslint:disable tsr-detect-non-literal-fs-filename
|
2 | 2 | import { expect } from "chai";
|
3 | 3 | import * as fs from "fs-extra";
|
4 |
| -import { dump as dumpYaml } from "js-yaml"; |
| 4 | +import { dump as dumpYaml, load as loadYaml } from "js-yaml"; |
5 | 5 | import * as path from "path";
|
6 | 6 | import { CompilerFunction, NodeVM } from "vm2";
|
7 | 7 |
|
8 |
| -import { decode64, encode64 } from "df/common/protos"; |
| 8 | +import { decode64, encode64, verifyObjectMatchesProto } from "df/common/protos"; |
9 | 9 | import { compile } from "df/core/compilers";
|
10 | 10 | import { version } from "df/core/version";
|
11 | 11 | import { dataform } from "df/protos/ts";
|
12 | 12 | import { asPlainObject, suite, test } from "df/testing";
|
13 | 13 | import { TmpDirFixture } from "df/testing/fixtures";
|
14 | 14 |
|
| 15 | + |
15 | 16 | const SOURCE_EXTENSIONS = ["js", "sql", "sqlx", "yaml", "ipynb"];
|
16 | 17 |
|
17 | 18 | const VALID_WORKFLOW_SETTINGS_YAML = `
|
@@ -877,9 +878,7 @@ actions:
|
877 | 878 |
|
878 | 879 | test(`data preparations can be loaded via an actions config file`, () => {
|
879 | 880 | const projectDir = createSimpleDataPreparationProject();
|
880 |
| - fs.writeFileSync( |
881 |
| - path.join(projectDir, "definitions/data_preparation.yaml"), |
882 |
| - ` |
| 881 | + const dataPreparationYaml = ` |
883 | 882 | nodes:
|
884 | 883 | - id: node1
|
885 | 884 | source:
|
@@ -912,6 +911,23 @@ nodes:
|
912 | 911 | type: STRING
|
913 | 912 | mode: NULLABLE
|
914 | 913 | `
|
| 914 | + |
| 915 | + fs.writeFileSync( |
| 916 | + path.join(projectDir, "definitions/data_preparation.yaml"), |
| 917 | + dataPreparationYaml |
| 918 | + ); |
| 919 | + |
| 920 | + // Generate Base64 encoded representation of the YAML. |
| 921 | + const dataPreparationAsObject = loadYaml(dataPreparationYaml); |
| 922 | + const dataPreparationDefinition = verifyObjectMatchesProto( |
| 923 | + dataform.DataPreparationDefinition, |
| 924 | + dataPreparationAsObject as { |
| 925 | + [key: string]: any; |
| 926 | + } |
| 927 | + ); |
| 928 | + const base64encodedContents = encode64( |
| 929 | + dataform.DataPreparationDefinition, |
| 930 | + dataPreparationDefinition |
915 | 931 | );
|
916 | 932 |
|
917 | 933 | const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
|
@@ -945,62 +961,8 @@ nodes:
|
945 | 961 | }
|
946 | 962 | ],
|
947 | 963 | fileName: "definitions/data_preparation.yaml",
|
948 |
| - dataPreparation: { |
949 |
| - nodes: [ |
950 |
| - { |
951 |
| - id: "node1", |
952 |
| - source: { |
953 |
| - table: { |
954 |
| - dataset: "ds", |
955 |
| - project: "prj", |
956 |
| - table: "src" |
957 |
| - } |
958 |
| - }, |
959 |
| - destination: { |
960 |
| - table: { |
961 |
| - dataset: "ds", |
962 |
| - project: "prj", |
963 |
| - table: "dest" |
964 |
| - } |
965 |
| - }, |
966 |
| - generated: { |
967 |
| - destinationGenerated: { |
968 |
| - schema: { |
969 |
| - field: [ |
970 |
| - { |
971 |
| - mode: "NULLABLE", |
972 |
| - name: "a", |
973 |
| - type: "STRING" |
974 |
| - } |
975 |
| - ] |
976 |
| - } |
977 |
| - }, |
978 |
| - outputSchema: { |
979 |
| - field: [ |
980 |
| - { |
981 |
| - mode: "NULLABLE", |
982 |
| - name: "a", |
983 |
| - type: "INT64" |
984 |
| - } |
985 |
| - ] |
986 |
| - }, |
987 |
| - sourceGenerated: { |
988 |
| - sourceSchema: { |
989 |
| - tableSchema: { |
990 |
| - field: [ |
991 |
| - { |
992 |
| - mode: "NULLABLE", |
993 |
| - name: "a", |
994 |
| - type: "STRING" |
995 |
| - } |
996 |
| - ] |
997 |
| - } |
998 |
| - } |
999 |
| - } |
1000 |
| - } |
1001 |
| - } |
1002 |
| - ] |
1003 |
| - } |
| 964 | + // Base64 encoded representation of the data preparation definition proto. |
| 965 | + dataPreparationContents: base64encodedContents |
1004 | 966 | }
|
1005 | 967 | ])
|
1006 | 968 | );
|
|
0 commit comments