Пример #1
0
func testStorageStoreRetrieveImage(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveImage("img-1", "id1", "host-1.something")
	defer storage.RemoveImage("img-1", "id1", "host-2")
	defer storage.RemoveImage("img-1", "id2", "host-2")
	err := storage.StoreImage("img-1", "id1", "host-1.something")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "id1", "host-2")
	assertIsNil(err, t)
	img, err := storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	expected := cluster.Image{Repository: "img-1", LastId: "id1", LastNode: "host-2", History: []cluster.ImageHistory{{
		Node:    "host-1.something",
		ImageId: "id1",
	}, {
		Node:    "host-2",
		ImageId: "id1",
	}}}
	compareImage(img, expected, t)
	err = storage.StoreImage("img-1", "id2", "host-2")
	assertIsNil(err, t)
	expected.History = append(expected.History, cluster.ImageHistory{Node: "host-2", ImageId: "id2"})
	expected.LastId = "id2"
	img, err = storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	compareImage(img, expected, t)
}
Пример #2
0
func testStorageStoreRemoveImage(storage cluster.Storage, t *testing.T) {
	err := storage.StoreImage("img-1", "id1", "host-1")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "id1", "host-2")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "id2", "host-2")
	assertIsNil(err, t)
	expected := cluster.Image{Repository: "img-1", LastId: "id2", LastNode: "host-2", History: []cluster.ImageHistory{{
		Node:    "host-1",
		ImageId: "id1",
	}, {
		Node:    "host-2",
		ImageId: "id1",
	}, {
		Node:    "host-2",
		ImageId: "id2",
	}}}
	img, err := storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	compareImage(img, expected, t)
	err = storage.RemoveImage("img-1", "id1", "host-1")
	assertIsNil(err, t)
	expected.History = []cluster.ImageHistory{{
		Node:    "host-2",
		ImageId: "id1",
	}, {
		Node:    "host-2",
		ImageId: "id2",
	}}
	img, err = storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	compareImage(img, expected, t)
	err = storage.RemoveImage("img-1", "id1", "host-2")
	assertIsNil(err, t)
	expected.History = []cluster.ImageHistory{{
		Node:    "host-2",
		ImageId: "id2",
	}}
	img, err = storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	compareImage(img, expected, t)
	err = storage.RemoveImage("img-1", "id2", "host-2")
	_, err = storage.RetrieveImage("img-1")
	if err != cstorage.ErrNoSuchImage {
		t.Fatalf("Expected error to be ErrNoSuchImage, got %s", err)
	}
}