Skip to content

Commit

Permalink
Use "canonical" names for containers. (microsoft#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphoff authored Jan 9, 2020
1 parent 5906baa commit 7975729
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/
12 changes: 11 additions & 1 deletion src/tree/containers/LocalContainerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/tree/containersTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateCreatedTimeInSec, ITestTreeItem, IValidateTreeOptions, validate
const testContainers: Partial<ContainerInfo>[] = [
{
Id: "9330566c414439f4873edd95689b559466993681f7b9741005b5a74786134202",
Names: ["/vigorous_booth"],
Names: ["/containera/vba", "/vigorous_booth", "/containerb/vbb"],
Image: "node:8.0",
ImageID: "sha256:065e283f68bd5ef3b079aee76d3aa55b5e56e8f9ede991a97ff15fdc556f8cfd",
Created: generateCreatedTimeInSec(1),
Expand Down

0 comments on commit 7975729

Please sign in to comment.