-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle filters reference more like Docker does
Currently we match *reference*, which is incorrect. Docker hard codes the current registry and matches the reference exactly, allowing users to pass in globs. This fix will truncate the registry name and localhost/ as well has the constant library/ off of images and then attempt to match. Helps Fix: containers/podman#11905 Signed-off-by: Daniel J Walsh <[email protected]>
- Loading branch information
Showing
3 changed files
with
118 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package libimage | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFilterNames(t *testing.T) { | ||
registries := []string{ | ||
"localhost", | ||
"docker.io", | ||
"foo.bar", | ||
"registry.access.redhat.com", | ||
} | ||
names := []string{ | ||
"docker.io/library/alpine:latest", | ||
"docker.io/library/busybox:latest", | ||
"docker.io/library/golang:1.13", | ||
"docker.io/library/golang:1.16", | ||
"docker.io/library/hello-world:latest", | ||
"docker.io/library/nginx:latest", | ||
"docker.io/library/traefik:2.2", | ||
"docker.io/syncthing/syncthing:1.18.4", | ||
"localhost/dan:latest", | ||
"localhost/darkside-image:latest", | ||
"localhost/myimage:latest", | ||
"localhost/mysystemd:latest", | ||
"localhost/restapi_app:latest", | ||
"localhost/restapi_backend:latest", | ||
"<none>:<none>", | ||
"quay.io/libpod/testimage:20210610", | ||
"quay.io/rhatdan/myimage:latest", | ||
"registry.access.redhat.com/ubi8-init:latest", | ||
"registry.access.redhat.com/ubi8:latest", | ||
"registry.access.redhat.com/ubi8-micro:latest", | ||
"registry.fedoraproject.org/fedora:latest", | ||
} | ||
|
||
for _, test := range []struct { | ||
filter string | ||
matches int | ||
}{ | ||
{"alpine", 1}, | ||
{"alpine*", 1}, | ||
{"localhost/restapi_app:latest", 1}, | ||
{"golang", 2}, | ||
{"golang:1.13", 1}, | ||
{"ubi8", 1}, | ||
{"ubi8*", 3}, | ||
{"myimage*", 1}, | ||
{"my*", 2}, | ||
{"*", len(names)}, | ||
{"*:latest", 15}, | ||
{"localhost/mysystemd", 1}, | ||
} { | ||
filter := setupFilter(test.filter) | ||
var imgs []string | ||
for _, name := range names { | ||
if ok, _ := filterNames(filter, []string{name}, registries); ok { | ||
imgs = append(imgs, name) | ||
} | ||
} | ||
|
||
fmt.Println(test.filter) | ||
require.Len(t, imgs, test.matches) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters