From 79757291813880a4de57447fc3d0dcf7457cefb8 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 8 Jan 2020 17:04:20 -0800 Subject: [PATCH] Use "canonical" names for containers. (#1534) --- .eslintignore | 1 + src/tree/containers/LocalContainerInfo.ts | 12 +++++++++++- test/tree/containersTree.test.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..65e3ba2eda --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +test/ diff --git a/src/tree/containers/LocalContainerInfo.ts b/src/tree/containers/LocalContainerInfo.ts index b72220553c..3ae7646301 100644 --- a/src/tree/containers/LocalContainerInfo.ts +++ b/src/tree/containers/LocalContainerInfo.ts @@ -10,6 +10,7 @@ import { ILocalImageInfo } from "../images/LocalImageInfo"; * Wrapper class for Dockerode item, which has inconsistent names/types */ export class LocalContainerInfo implements ILocalImageInfo { + private _containerName: string; public data: ContainerInfo; public constructor(data: ContainerInfo) { this.data = data; @@ -24,7 +25,16 @@ export class LocalContainerInfo implements ILocalImageInfo { } public get containerName(): string { - return this.data.Names[0].substr(1); // Remove start '/' + if (!this._containerName) { + const names = this.data.Names.map(name => name.substr(1)); // Remove start '/' + + // Linked containers may have names containing '/'; their one "canonical" names will not. + const canonicalName = names.find(name => name.indexOf('/') === -1); + + this._containerName = canonicalName ?? names[0]; + } + + return this._containerName; } public get fullTag(): string { diff --git a/test/tree/containersTree.test.ts b/test/tree/containersTree.test.ts index d06712f9ce..850c1080a1 100644 --- a/test/tree/containersTree.test.ts +++ b/test/tree/containersTree.test.ts @@ -11,7 +11,7 @@ import { generateCreatedTimeInSec, ITestTreeItem, IValidateTreeOptions, validate const testContainers: Partial[] = [ { Id: "9330566c414439f4873edd95689b559466993681f7b9741005b5a74786134202", - Names: ["/vigorous_booth"], + Names: ["/containera/vba", "/vigorous_booth", "/containerb/vbb"], Image: "node:8.0", ImageID: "sha256:065e283f68bd5ef3b079aee76d3aa55b5e56e8f9ede991a97ff15fdc556f8cfd", Created: generateCreatedTimeInSec(1),