Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
[HOUSEKEEPING] resolve page wide no-non-null-assertion eslint-disable (
Browse files Browse the repository at this point in the history
…#468)

* [HOUSEKEEPING] resolve page wide no-non-null-assertion eslint-disable

* Update generate.test.ts

* Update shell.ts
  • Loading branch information
dennisseah authored Mar 30, 2020
1 parent 9e4b663 commit b160efe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
16 changes: 14 additions & 2 deletions src/commands/infra/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ describe("fetch execute function", () => {
jest
.spyOn(generate, "validateDefinition")
.mockReturnValueOnce(DefinitionYAMLExistence.PARENT_ONLY);
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({});
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({
source: "",
template: "",
version: "",
});
jest.spyOn(generate, "validateRemoteSource").mockResolvedValueOnce();
jest
.spyOn(infraCommon, "getSourceFolderNameFromURL")
Expand All @@ -293,7 +297,11 @@ describe("fetch execute function", () => {
.spyOn(generate, "validateDefinition")
.mockReturnValueOnce(DefinitionYAMLExistence.BOTH_EXIST);
jest.spyOn(generate, "validateRemoteSource").mockResolvedValueOnce();
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({});
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({
source: "",
template: "",
version: "",
});
jest
.spyOn(generate, "generateConfig")
.mockReturnValueOnce(Promise.resolve());
Expand Down Expand Up @@ -324,6 +332,7 @@ describe("test validateRemoteSource function", () => {

await validateRemoteSource({
source: "source",
template: "",
version: "0.1",
});
});
Expand All @@ -339,6 +348,7 @@ describe("test validateRemoteSource function", () => {

await validateRemoteSource({
source: "source",
template: "",
version: "0.1",
});
});
Expand All @@ -354,6 +364,7 @@ describe("test validateRemoteSource function", () => {

await validateRemoteSource({
source: "source",
template: "",
version: "0.1",
});
});
Expand All @@ -370,6 +381,7 @@ describe("test validateRemoteSource function", () => {
try {
await validateRemoteSource({
source: "source",
template: "",
version: "0.1",
});
expect(true).toBe(false);
Expand Down
43 changes: 25 additions & 18 deletions src/commands/infra/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-use-before-define */
import commander from "commander";
import fs from "fs";
Expand Down Expand Up @@ -31,9 +30,9 @@ interface CommandOptions {
}

export interface SourceInformation {
source?: string;
template?: string;
version?: string;
source: string;
template: string;
version: string;
}

export enum DefinitionYAMLExistence {
Expand All @@ -57,6 +56,8 @@ export const execute = async (
parentPath,
projectPath
);
// validateTemplateSources makes sure that
// sourceConfig has values for source, template and version
await validateRemoteSource(sourceConfig);
await generateConfig(
parentPath,
Expand Down Expand Up @@ -142,7 +143,11 @@ export const validateTemplateSources = (
const sourceKeys = ["source", "template", "version"] as Array<
keyof SourceInformation
>;
const source: SourceInformation = {};
const source: SourceInformation = {
source: "",
template: "",
version: "",
};
let parentInfraConfig: InfraConfigYaml;
let leafInfraConfig: InfraConfigYaml;

Expand All @@ -163,18 +168,18 @@ export const validateTemplateSources = (
source[k] = parentInfraConfig[k];
}
});
if (!source.source || !source.template || !source.version) {
throw new Error(
`The ${DEFINITION_YAML} file is invalid. \
There is a missing field for it's sources. \
Template: ${source.template} source: ${source.source} version: ${source.version}`
if (source.source && source.template && source.version) {
const safeLoggingUrl = safeGitUrlForLogging(source.source);
logger.info(
`Checking for locally stored template: ${source.template} from remote repository: ${safeLoggingUrl} at version: ${source.version}`
);
return source;
}
const safeLoggingUrl = safeGitUrlForLogging(source.source!);
logger.info(
`Checking for locally stored template: ${source.template} from remote repository: ${safeLoggingUrl} at version: ${source.version}`
throw new Error(
`The ${DEFINITION_YAML} file is invalid. \
There is a missing field for it's sources. \
Template: ${source.template} source: ${source.source} version: ${source.version}`
);
return source;
};

export const checkRemoteGitExist = async (
Expand Down Expand Up @@ -226,8 +231,8 @@ export const gitCheckout = async (
export const validateRemoteSource = async (
sourceConfig: SourceInformation
): Promise<void> => {
const source = sourceConfig.source!;
const version = sourceConfig.version!;
const source = sourceConfig.source;
const version = sourceConfig.version;

// Converting source name to storable folder name
const sourceFolder = getSourceFolderNameFromURL(source);
Expand Down Expand Up @@ -378,11 +383,11 @@ export const generateConfig = async (
outputPath: string
): Promise<void> => {
const parentDirectory = getParentGeneratedFolder(parentPath, outputPath);
const sourceFolder = getSourceFolderNameFromURL(sourceConfig.source!);
const sourceFolder = getSourceFolderNameFromURL(sourceConfig.source);
const templatePath = path.join(
spkTemplatesPath,
sourceFolder,
sourceConfig.template!
sourceConfig.template
);
const childDirectory =
projectPath === parentPath
Expand All @@ -405,7 +410,9 @@ export const generateConfig = async (
}

combineVariable(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
parentInfraConfig.variables!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
leafInfraConfig.variables!,
childDirectory,
SPK_TFVARS
Expand Down
1 change: 0 additions & 1 deletion src/lib/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
import child_process from "child_process";
import { logger } from "../logger";

Expand Down

0 comments on commit b160efe

Please sign in to comment.