github.com/nguyentm83/docker@v1.5.0/graph/manifest_test.go (about) 1 package graph 2 3 import ( 4 "encoding/json" 5 "os" 6 "testing" 7 8 "github.com/docker/docker/image" 9 "github.com/docker/docker/registry" 10 "github.com/docker/docker/utils" 11 ) 12 13 const ( 14 testManifestImageName = "testapp" 15 testManifestImageID = "d821b739e8834ec89ac4469266c3d11515da88fdcbcbdddcbcddb636f54fdde9" 16 testManifestImageIDShort = "d821b739e883" 17 testManifestTag = "manifesttest" 18 ) 19 20 func TestManifestTarsumCache(t *testing.T) { 21 tmp, err := utils.TestDirectory("") 22 if err != nil { 23 t.Fatal(err) 24 } 25 defer os.RemoveAll(tmp) 26 store := mkTestTagStore(tmp, t) 27 defer store.graph.driver.Cleanup() 28 29 archive, err := fakeTar() 30 if err != nil { 31 t.Fatal(err) 32 } 33 img := &image.Image{ID: testManifestImageID} 34 if err := store.graph.Register(img, archive); err != nil { 35 t.Fatal(err) 36 } 37 if err := store.Set(testManifestImageName, testManifestTag, testManifestImageID, false); err != nil { 38 t.Fatal(err) 39 } 40 41 if cs, err := img.GetCheckSum(store.graph.ImageRoot(testManifestImageID)); err != nil { 42 t.Fatal(err) 43 } else if cs != "" { 44 t.Fatalf("Non-empty checksum file after register") 45 } 46 47 // Generate manifest 48 payload, err := store.newManifest(testManifestImageName, testManifestImageName, testManifestTag) 49 if err != nil { 50 t.Fatal(err) 51 } 52 53 manifestChecksum, err := img.GetCheckSum(store.graph.ImageRoot(testManifestImageID)) 54 if err != nil { 55 t.Fatal(err) 56 } 57 58 var manifest registry.ManifestData 59 if err := json.Unmarshal(payload, &manifest); err != nil { 60 t.Fatalf("error unmarshalling manifest: %s", err) 61 } 62 63 if len(manifest.FSLayers) != 1 { 64 t.Fatalf("Unexpected number of layers, expecting 1: %d", len(manifest.FSLayers)) 65 } 66 67 if manifest.FSLayers[0].BlobSum != manifestChecksum { 68 t.Fatalf("Unexpected blob sum, expecting %q, got %q", manifestChecksum, manifest.FSLayers[0].BlobSum) 69 } 70 71 if len(manifest.History) != 1 { 72 t.Fatalf("Unexpected number of layer history, expecting 1: %d", len(manifest.History)) 73 } 74 75 v1compat, err := img.RawJson() 76 if err != nil { 77 t.Fatal(err) 78 } 79 if manifest.History[0].V1Compatibility != string(v1compat) { 80 t.Fatalf("Unexpected json value\nExpected:\n%s\nActual:\n%s", v1compat, manifest.History[0].V1Compatibility) 81 } 82 }