Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

bedrock deployment get minor improvements #38

Merged
merged 21 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 6 additions & 1 deletion docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
{
"arg": "-t, --top <top>",
"description": "Return only top N most recent deployments",
"defaultValue": ""
"defaultValue": "50"
},
{
"arg": "-o, --output <output-format>",
Expand All @@ -164,6 +164,11 @@
"arg": "-w, --watch",
"description": "Watch the deployments for a live view",
"defaultValue": false
},
{
"arg": "--remove-separators",
"description": "Display the table without separators between columns",
"defaultValue": false
}
],
"markdown": "## Description\n\nThis commands retrieves the list of deployments by service name, release\nenvironment, build ID, commit ID, or container image tag.\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"open": "^6.4.0",
"shelljs": "^0.8.3",
"simple-git": "^1.126.0",
"spektate": "^1.0.6",
"spektate": "^1.0.11",
"ssh-url": "^0.1.5",
"uuid": "^3.3.3",
"winston": "^3.2.1"
Expand Down
7 changes: 6 additions & 1 deletion src/commands/deployment/get.decorator.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{
"arg": "-t, --top <top>",
"description": "Return only top N most recent deployments",
"defaultValue": ""
"defaultValue": "50"
},
{
"arg": "-o, --output <output-format>",
Expand All @@ -47,6 +47,11 @@
"arg": "-w, --watch",
"description": "Watch the deployments for a live view",
"defaultValue": false
},
{
"arg": "--remove-separators",
samiyaakhtar marked this conversation as resolved.
Show resolved Hide resolved
"description": "Display the table without separators between columns",
"defaultValue": false
}
]
}
81 changes: 68 additions & 13 deletions src/commands/deployment/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const MOCKED_INPUT_VALUES: CommandOptions = {
service: "",
top: "",
watch: false,
removeSeparators: false,
};

const MOCKED_VALUES: ValidatedOptions = {
Expand All @@ -53,6 +54,7 @@ const MOCKED_VALUES: ValidatedOptions = {
service: "",
top: "",
watch: false,
removeSeparators: false,
};

const getMockedInputValues = (): CommandOptions => {
Expand All @@ -70,9 +72,11 @@ const fakeDeployments = data;
const fakeClusterSyncs = require("./mocks/cluster-sync.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fakePR = require("./mocks/pr.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fakeAuthor = require("./mocks/author.json");
const mockedDeps: IDeployment[] = fakeDeployments.data.map(
(dep: IDeployment) => {
return {
const newDep = {
commitId: dep.commitId,
deploymentId: dep.deploymentId,
dockerToHldRelease: dep.dockerToHldRelease,
Expand All @@ -90,6 +94,21 @@ const mockedDeps: IDeployment[] = fakeDeployments.data.map(
srcToDockerBuild: dep.srcToDockerBuild,
timeStamp: dep.timeStamp,
};
// Since json data has dates in string format, convert them to dates
const builds = [
newDep.srcToDockerBuild,
newDep.hldToManifestBuild,
newDep.dockerToHldRelease,
newDep.dockerToHldReleaseStage,
];
builds.forEach((build) => {
if (build) {
build.startTime = new Date(build.startTime);
build.queueTime = new Date(build.queueTime);
build.finishTime = new Date(build.finishTime);
}
});
return newDep;
}
);

Expand All @@ -103,6 +122,9 @@ jest
.spyOn(AzureDevOpsRepo, "getManifestSyncState")
.mockReturnValue(Promise.resolve(mockedClusterSyncs));
jest.spyOn(Deployment, "fetchPR").mockReturnValue(Promise.resolve(fakePR));
jest
.spyOn(Deployment, "fetchAuthor")
.mockReturnValue(Promise.resolve(fakeAuthor));

let initObject: InitObject;

Expand Down Expand Up @@ -130,7 +152,7 @@ describe("Test getStatus function", () => {
expect(getStatus("succeeded")).toBe("\u2713");
});
it("with empty string as value", () => {
expect(getStatus("")).toBe("...");
expect(getStatus("")).toBe("");
});
it("with other string as value", () => {
expect(getStatus("test")).toBe("\u0445");
Expand Down Expand Up @@ -314,36 +336,40 @@ describe("Print deployments", () => {
mockedDeps,
processOutputFormat("normal"),
undefined,
mockedClusterSyncs
mockedClusterSyncs,
true
);
expect(table).not.toBeUndefined();
const deployment = [
"2019-08-30T21:05:19.047Z",
"Complete",
"hello-bedrock",
"c626394",
6046,
"dev",
"hello-bedrock-master-6046",
6046,
"c626394",
"✓",
180,
"DEV",
"706685f",
"✓",
6047,
"b3a3345",
"✓",
"EUROPE",
"3.41 mins",
];

expect(table).toBeDefined();

if (table) {
//Use date (index 0) as matching filter
const matchItems = table.filter((field) => field[0] === deployment[0]);
// Use image tag (index 3) as matching filter
const matchItems = table.filter(
(field: any) => field[3] === deployment[3]
);
expect(matchItems).toHaveLength(1); // one matching row

(matchItems[0] as IDeployment[]).forEach((field, i) => {
expect(field).toEqual(deployment[i]);
});
expect(matchItems[0]).toHaveLength(13);
expect(matchItems[0]).toHaveLength(14);

table = printDeployments(
mockedDeps,
Expand Down Expand Up @@ -385,16 +411,45 @@ describe("Cluster sync", () => {

describe("Output formats", () => {
test("verify wide output", () => {
const table = printDeployments(
let table = printDeployments(
mockedDeps,
processOutputFormat("wide"),
undefined,
mockedClusterSyncs,
false
);
expect(table).toBeDefined();

if (table) {
table.forEach((field) => expect(field).toHaveLength(23));
}

table = printDeployments(
mockedDeps,
processOutputFormat("wide"),
undefined,
mockedClusterSyncs
mockedClusterSyncs,
true
);
expect(table).toBeDefined();

if (table) {
table.forEach((field) => expect(field).toHaveLength(19));
}
});
test("verify json output", () => {
MOCKED_VALUES.outputFormat = OUTPUT_FORMAT.JSON;
const consoleSpy = jest.spyOn(console, "log");
const table = get.displayDeployments(
MOCKED_VALUES,
mockedDeps,
mockedClusterSyncs,
initObject
);
expect(table).toBeDefined();
expect(consoleSpy).toHaveBeenCalled();
expect(consoleSpy).toHaveBeenCalledWith(
JSON.stringify(mockedDeps, null, 2)
);
});
});
Loading