mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-06 11:42:34 +02:00
fix: improved docker image parsing
This commit is contained in:
parent
3135e377a9
commit
e39407886d
2 changed files with 40 additions and 0 deletions
|
@ -48,10 +48,13 @@ func (c containerHelper) parseImage() *ContainerImage {
|
|||
im.Author = strings.Join(slashSep[:len(slashSep)-1], "/")
|
||||
im.Name = slashSep[len(slashSep)-1]
|
||||
} else {
|
||||
im.Author = "library"
|
||||
im.Name = slashSep[0]
|
||||
}
|
||||
if len(colonSep) > 1 {
|
||||
im.Tag = colonSep[1]
|
||||
} else {
|
||||
im.Tag = "latest"
|
||||
}
|
||||
return im
|
||||
}
|
||||
|
|
|
@ -76,3 +76,40 @@ func TestContainerHostNetworkMode(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageNameParsing(t *testing.T) {
|
||||
tests := []struct {
|
||||
full string
|
||||
author string
|
||||
image string
|
||||
tag string
|
||||
}{
|
||||
{
|
||||
full: "ghcr.io/tensorchord/pgvecto-rs",
|
||||
author: "ghcr.io/tensorchord",
|
||||
image: "pgvecto-rs",
|
||||
tag: "latest",
|
||||
},
|
||||
{
|
||||
full: "redis:latest",
|
||||
author: "library",
|
||||
image: "redis",
|
||||
tag: "latest",
|
||||
},
|
||||
{
|
||||
full: "redis:7.4.0-alpine",
|
||||
author: "library",
|
||||
image: "redis",
|
||||
tag: "7.4.0-alpine",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.full, func(t *testing.T) {
|
||||
helper := containerHelper{&container.SummaryTrimmed{Image: tt.full}}
|
||||
im := helper.parseImage()
|
||||
ExpectEqual(t, im.Author, tt.author)
|
||||
ExpectEqual(t, im.Name, tt.image)
|
||||
ExpectEqual(t, im.Tag, tt.tag)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue