Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "canonical" names for containers. #1534

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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