Skip to content

Commit

Permalink
Merge pull request moby#48682 from thaJeztah/remove_formatPlatform
Browse files Browse the repository at this point in the history
distribution: remove formatPlatform utility
  • Loading branch information
AkihiroSuda authored Oct 17, 2024
2 parents 6649a32 + e7e555f commit 921ac59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
8 changes: 7 additions & 1 deletion distribution/pull_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,13 @@ type noMatchesErr struct {
}

func (e noMatchesErr) Error() string {
return fmt.Sprintf("no matching manifest for %s in the manifest list entries", formatPlatform(e.platform))
var p string
if e.platform.OS == "" {
p = platforms.FormatAll(platforms.DefaultSpec())
} else {
p = platforms.FormatAll(e.platform)
}
return fmt.Sprintf("no matching manifest for %s in the manifest list entries", p)
}

func retry(ctx context.Context, maxAttempts int, sleep time.Duration, f func(ctx context.Context) error) (err error) {
Expand Down
30 changes: 11 additions & 19 deletions distribution/pull_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/url"
"os"
"reflect"
"regexp"
"runtime"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -193,24 +192,17 @@ func TestValidateManifest(t *testing.T) {
}
}

func TestFormatPlatform(t *testing.T) {
var platform ocispec.Platform
result := formatPlatform(platform)
if strings.HasPrefix(result, "unknown") {
t.Fatal("expected formatPlatform to show a known platform")
}
if !strings.HasPrefix(result, runtime.GOOS) {
t.Fatal("expected formatPlatform to show the current platform")
}
if runtime.GOOS == "windows" {
if !strings.HasPrefix(result, "windows") {
t.Fatal("expected formatPlatform to show windows platform")
}
matches, _ := regexp.MatchString("windows.* [0-9]", result)
if !matches {
t.Fatalf("expected formatPlatform to show windows platform with a version, but got '%s'", result)
}
}
func TestNoMatchesErr(t *testing.T) {
err := noMatchesErr{}
assert.Check(t, is.ErrorContains(err, "no matching manifest for "+runtime.GOOS))

err = noMatchesErr{ocispec.Platform{
Architecture: "arm64",
OS: "windows",
OSVersion: "10.0.17763",
Variant: "v8",
}}
assert.Check(t, is.Error(err, "no matching manifest for windows(10.0.17763)/arm64/v8 in the manifest list entries"))
}

func TestPullSchema2Config(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions distribution/pull_v2_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,3 @@ func withDefault(p ocispec.Platform) ocispec.Platform {
}
return p
}

func formatPlatform(platform ocispec.Platform) string {
if platform.OS == "" {
platform = platforms.DefaultSpec()
}
return platforms.Format(platform)
}
8 changes: 0 additions & 8 deletions distribution/pull_v2_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/Microsoft/hcsshim/osversion"
"github.com/containerd/log"
"github.com/containerd/platforms"
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist"
"github.com/docker/distribution/manifest/schema2"
Expand Down Expand Up @@ -151,10 +150,3 @@ func checkImageCompatibility(imageOS, imageOSVersion string) error {
}
return nil
}

func formatPlatform(platform ocispec.Platform) string {
if platform.OS == "" {
platform = platforms.DefaultSpec()
}
return fmt.Sprintf("%s %s", platforms.Format(platform), osversion.Get().ToString())
}

0 comments on commit 921ac59

Please sign in to comment.