Files
Pulse/internal/dockeragent/image_ref_test.go
rcourtman 053a40d7df fix: Docker container update detection showing false positives
Fixed an issue where all Docker containers were showing 'click to update'
even when they were up to date. The root cause was comparing the wrong
digest types:

- Previously: Compared ImageID (local config hash) vs registry manifest digest
- Now: Uses RepoDigests from image inspect, which is the actual manifest
  digest that Docker received from the registry when pulling the image

For multi-arch images, the registry returns a manifest list digest, while
Docker stores the platform-specific image config digest locally. These
will never match, causing false positives for all multi-arch images.

Changes:
- Added ImageInspectWithRaw to dockerClient interface
- Added getImageRepoDigest method to extract RepoDigest from image
- Added matchesImageReference helper for Docker Hub naming conventions
- Added tests for matchesImageReference

Fixes #955
2025-12-29 13:49:04 +00:00

95 lines
2.1 KiB
Go

package dockeragent
import "testing"
func TestMatchesImageReference(t *testing.T) {
tests := []struct {
name string
imageName string
repoRef string
want bool
}{
{
name: "exact match",
imageName: "nginx",
repoRef: "nginx",
want: true,
},
{
name: "docker hub library image",
imageName: "nginx",
repoRef: "docker.io/library/nginx",
want: true,
},
{
name: "docker hub library image with tag",
imageName: "nginx:latest",
repoRef: "docker.io/library/nginx",
want: true,
},
{
name: "docker hub library image with specific tag",
imageName: "nginx:1.25",
repoRef: "docker.io/library/nginx",
want: true,
},
{
name: "docker hub with namespace",
imageName: "myuser/myapp",
repoRef: "docker.io/myuser/myapp",
want: true,
},
{
name: "docker hub with namespace and tag",
imageName: "myuser/myapp:v1.0",
repoRef: "docker.io/myuser/myapp",
want: true,
},
{
name: "ghcr.io registry",
imageName: "ghcr.io/user/repo",
repoRef: "ghcr.io/user/repo",
want: true,
},
{
name: "ghcr.io registry with tag",
imageName: "ghcr.io/user/repo:latest",
repoRef: "ghcr.io/user/repo",
want: true,
},
{
name: "quay.io registry",
imageName: "quay.io/org/image",
repoRef: "quay.io/org/image",
want: true,
},
{
name: "different images should not match",
imageName: "nginx",
repoRef: "docker.io/library/redis",
want: false,
},
{
name: "different namespaces should not match",
imageName: "user1/app",
repoRef: "docker.io/user2/app",
want: false,
},
{
name: "image with port in registry should preserve port",
imageName: "localhost:5000/myimage:tag",
repoRef: "localhost:5000/myimage",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := matchesImageReference(tt.imageName, tt.repoRef)
if got != tt.want {
t.Errorf("matchesImageReference(%q, %q) = %v, want %v", tt.imageName, tt.repoRef, got, tt.want)
}
})
}
}