Fixed the tests.

This commit is contained in:
Filip Barl
2018-05-15 16:56:00 +02:00
parent 4382deb39b
commit 183aaea950
3 changed files with 14 additions and 9 deletions

View File

@@ -472,6 +472,7 @@ func (r *registry) WalkNetworks(f func(docker_client.Network)) {
}
}
// ImageNameParts returns parts of the full image name (image name, image tag).
func ImageNameParts(name string) []string {
parts := strings.SplitN(name, "/", 3)
if len(parts) == 3 {
@@ -488,5 +489,9 @@ func ImageNameWithoutVersion(name string) string {
// ImageNameVersion splits the image name apart, returning the version, if possible
func ImageNameVersion(name string) string {
return ImageNameParts(name)[1]
imageNameParts := ImageNameParts(name)
if len(imageNameParts) < 2 {
return ""
}
return imageNameParts[1]
}

View File

@@ -195,9 +195,9 @@ func TestMakeDetailedContainerNode(t *testing.T) {
Pseudo: false,
},
Metadata: []report.MetadataRow{
{ID: "docker_image_name", Label: "Image", Value: fixture.ServerContainerImageName, Priority: 1},
{ID: "docker_container_state_human", Label: "State", Value: "running", Priority: 3},
{ID: "docker_container_id", Label: "ID", Value: fixture.ServerContainerID, Priority: 10, Truncate: 12},
{ID: "docker_image_name", Label: "Image name", Value: fixture.ServerContainerImageName, Priority: 2},
{ID: "docker_container_state_human", Label: "State", Value: "running", Priority: 4},
{ID: "docker_container_id", Label: "ID", Value: fixture.ServerContainerID, Priority: 11, Truncate: 12},
},
Metrics: []report.MetricRow{
{

View File

@@ -132,8 +132,8 @@ func TestMakeNodeSummary(t *testing.T) {
Shape: "hexagon",
},
Metadata: []report.MetadataRow{
{ID: docker.ImageName, Label: "Image", Value: fixture.ClientContainerImageName, Priority: 1},
{ID: docker.ContainerID, Label: "ID", Value: fixture.ClientContainerID, Priority: 10, Truncate: 12},
{ID: docker.ImageName, Label: "Image name", Value: fixture.ClientContainerImageName, Priority: 2},
{ID: docker.ContainerID, Label: "ID", Value: fixture.ClientContainerID, Priority: 11, Truncate: 12},
},
Adjacency: report.MakeIDList(fixture.ServerContainerNodeID),
},
@@ -252,9 +252,9 @@ func TestNodeMetadata(t *testing.T) {
Add(docker.ContainerIPs, report.MakeStringSet("10.10.10.0/24", "10.10.10.1/24")),
),
want: []report.MetadataRow{
{ID: docker.ContainerStateHuman, Label: "State", Value: "running", Priority: 3},
{ID: docker.ContainerIPs, Label: "IPs", Value: "10.10.10.0/24, 10.10.10.1/24", Priority: 7},
{ID: docker.ContainerID, Label: "ID", Value: fixture.ClientContainerID, Priority: 10, Truncate: 12},
{ID: docker.ContainerStateHuman, Label: "State", Value: "running", Priority: 4},
{ID: docker.ContainerIPs, Label: "IPs", Value: "10.10.10.0/24, 10.10.10.1/24", Priority: 8},
{ID: docker.ContainerID, Label: "ID", Value: fixture.ClientContainerID, Priority: 11, Truncate: 12},
},
},
{