client: TestImageHistory: add minimal test for platform

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-11-05 13:18:51 +01:00
parent 73fabd5a21
commit 083d595286

View File

@@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/errdefs"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@@ -23,12 +24,14 @@ func TestImageHistoryError(t *testing.T) {
func TestImageHistory(t *testing.T) {
const (
expectedURL = "/images/image_id/history"
historyResponse = `[{"Comment":"","Created":0,"CreatedBy":"","Id":"image_id1","Size":0,"Tags":["tag1","tag2"]},{"Comment":"","Created":0,"CreatedBy":"","Id":"image_id2","Size":0,"Tags":["tag1","tag2"]}]`
expectedURL = "/images/image_id/history"
historyResponse = `[{"Comment":"","Created":0,"CreatedBy":"","Id":"image_id1","Size":0,"Tags":["tag1","tag2"]},{"Comment":"","Created":0,"CreatedBy":"","Id":"image_id2","Size":0,"Tags":["tag1","tag2"]}]`
expectedPlatform = `{"architecture":"arm64","os":"linux","variant":"v8"}`
)
client := &Client{
client: newMockClient(func(r *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(r.URL.Path, expectedURL))
assert.Check(t, is.Equal(r.URL.Query().Get("platform"), expectedPlatform))
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(historyResponse)),
@@ -46,7 +49,13 @@ func TestImageHistory(t *testing.T) {
},
}
imageHistories, err := client.ImageHistory(context.Background(), "image_id", image.HistoryOptions{})
imageHistories, err := client.ImageHistory(context.Background(), "image_id", image.HistoryOptions{
Platform: &ocispec.Platform{
Architecture: "arm64",
OS: "linux",
Variant: "v8",
},
})
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(imageHistories, expected))
}