platforms: provide simpler function for common use

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-09-20 11:56:59 -07:00
parent f41871be9d
commit 9163377123
8 changed files with 23 additions and 13 deletions

View File

@@ -6,8 +6,13 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1"
)
// Default returns the current platform's default platform specification.
func Default() specs.Platform {
// Default returns the default specifier for the platform.
func Default() string {
return Format(DefaultSpec())
}
// DefaultSpec returns the current platform's default platform specification.
func DefaultSpec() specs.Platform {
return specs.Platform{
OS: runtime.GOOS,
Architecture: runtime.GOARCH,

View File

@@ -13,8 +13,13 @@ func TestDefault(t *testing.T) {
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
}
p := Default()
p := DefaultSpec()
if !reflect.DeepEqual(p, expected) {
t.Fatalf("default platform not as expected: %#v != %#v", p, expected)
}
s := Default()
if s != Format(p) {
t.Fatalf("default specifier should match formatted default spec: %v != %v", s, p)
}
}