Browse Source

Merge pull request #34878 from chchliang/imagebranch

Add  testcases with ` Image` , covering all methods.
Sebastiaan van Stijn 7 years ago
parent
commit
ba317637de
1 changed files with 34 additions and 0 deletions
  1. 34 0
      image/image_test.go

+ 34 - 0
image/image_test.go

@@ -2,6 +2,7 @@ package image
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"runtime"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -54,6 +55,39 @@ func TestMarshalKeyOrder(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestImage(t *testing.T) {
+	cid := "50a16564e727"
+	config := &container.Config{
+		Hostname:   "hostname",
+		Domainname: "domain",
+		User:       "root",
+	}
+	platform := runtime.GOOS
+
+	img := &Image{
+		V1Image: V1Image{
+			Config: config,
+		},
+		computedID: ID(cid),
+	}
+
+	assert.Equal(t, cid, img.ImageID())
+	assert.Equal(t, cid, img.ID().String())
+	assert.Equal(t, platform, img.Platform())
+	assert.Equal(t, config, img.RunConfig())
+}
+
+func TestImagePlatformNotEmpty(t *testing.T) {
+	platform := "platform"
+	img := &Image{
+		V1Image: V1Image{
+			OS: platform,
+		},
+		OSVersion: "osversion",
+	}
+	assert.Equal(t, platform, img.Platform())
+}
+
 func TestNewChildImageFromImageWithRootFS(t *testing.T) {
 func TestNewChildImageFromImageWithRootFS(t *testing.T) {
 	rootFS := NewRootFS()
 	rootFS := NewRootFS()
 	rootFS.Append(layer.DiffID("ba5e"))
 	rootFS.Append(layer.DiffID("ba5e"))