|
@@ -2,8 +2,10 @@ package distribution // import "github.com/docker/docker/distribution"
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"reflect"
|
|
"reflect"
|
|
|
|
+ "regexp"
|
|
"runtime"
|
|
"runtime"
|
|
"strings"
|
|
"strings"
|
|
"testing"
|
|
"testing"
|
|
@@ -11,6 +13,7 @@ import (
|
|
"github.com/docker/distribution/manifest/schema1"
|
|
"github.com/docker/distribution/manifest/schema1"
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/opencontainers/go-digest"
|
|
"github.com/opencontainers/go-digest"
|
|
|
|
+ specs "github.com/opencontainers/image-spec/specs-go/v1"
|
|
"gotest.tools/assert"
|
|
"gotest.tools/assert"
|
|
is "gotest.tools/assert/cmp"
|
|
is "gotest.tools/assert/cmp"
|
|
)
|
|
)
|
|
@@ -182,3 +185,23 @@ func TestValidateManifest(t *testing.T) {
|
|
t.Fatal("expected validateManifest to fail with digest error")
|
|
t.Fatal("expected validateManifest to fail with digest error")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestFormatPlatform(t *testing.T) {
|
|
|
|
+ var platform specs.Platform
|
|
|
|
+ var 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.Fatal(fmt.Sprintf("expected formatPlatform to show windows platform with a version, but got '%s'", result))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|