Exemple #1
0
func TestListImagesPopulatedList(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Images = &api.ImageList{
		Items: []api.Image{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "foo",
				},
			},
			{
				JSONBase: kubeapi.JSONBase{
					ID: "bar",
				},
			},
		},
	}

	storage := ImageStorage{
		registry: mockRegistry,
	}

	list, err := storage.List(labels.Everything())
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	images := list.(*api.ImageList)

	if e, a := 2, len(images.Items); e != a {
		t.Errorf("Expected %v, got %v", e, a)
	}
}
func TestCreateImageRepositoryMappingFindError(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	imageRepositoryRegistry.Err = fmt.Errorf("123")
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	mapping := api.ImageRepositoryMapping{
		DockerImageRepository: "localhost:5000/someproject/somerepo",
		Image: api.Image{
			JSONBase: kubeapi.JSONBase{
				ID: "imageID1",
			},
			DockerImageReference: "localhost:5000/someproject/somerepo:imageID1",
		},
		Tag: "latest",
	}

	channel, err := storage.Create(&mapping)
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil || err.Error() != "123" {
		t.Errorf("Expected 'unable to locate' error, got %#v", err)
	}
}
func TestCreateImageRepositoryMappingNotFound(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	imageRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "repo1",
				},
				DockerImageRepository: "localhost:5000/test/repo",
			},
		},
	}
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	mapping := api.ImageRepositoryMapping{
		DockerImageRepository: "localhost:5000/someproject/somerepo",
		Image: api.Image{
			JSONBase: kubeapi.JSONBase{
				ID: "imageID1",
			},
			DockerImageReference: "localhost:5000/someproject/somerepo:imageID1",
		},
		Tag: "latest",
	}

	channel, err := storage.Create(&mapping)
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil || strings.Index(err.Error(), "Unable to locate an image repository") == -1 {
		t.Errorf("Expected 'unable to locate' error, got %#v", err)
	}
}
Exemple #4
0
func TestDeleteImage(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	storage := ImageStorage{registry: mockRegistry}
	channel, err := storage.Delete("foo")
	if channel == nil {
		t.Error("Unexpected nil channel")
	}
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	select {
	case result := <-channel:
		status, ok := result.(*kubeapi.Status)
		if !ok {
			t.Errorf("Expected status type, got: %#v", result)
		}
		if status.Status != "success" {
			t.Errorf("Expected status=success, got: %#v", status)
		}
	case <-time.After(50 * time.Millisecond):
		t.Errorf("Timed out waiting for result")
	default:
	}
}
Exemple #5
0
func TestCreateImageOK(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	storage := ImageStorage{registry: mockRegistry}

	channel, err := storage.Create(&api.Image{
		JSONBase:             kubeapi.JSONBase{ID: "foo"},
		DockerImageReference: "openshift/ruby-19-centos",
	})
	if channel == nil {
		t.Errorf("Expected nil channel, got %v", channel)
	}
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	select {
	case result := <-channel:
		image, ok := result.(*api.Image)
		if !ok {
			t.Errorf("Expected image type, got: %#v", result)
		}
		if image.ID != "foo" {
			t.Errorf("Unexpected image: %#v", image)
		}
	case <-time.After(50 * time.Millisecond):
		t.Errorf("Timed out waiting for result")
	default:
	}
}
Exemple #6
0
func TestCreateImageRegistrySaveError(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Err = fmt.Errorf("test error")
	storage := ImageStorage{registry: mockRegistry}

	channel, err := storage.Create(&api.Image{
		JSONBase:             kubeapi.JSONBase{ID: "foo"},
		DockerImageReference: "openshift/ruby-19-centos",
	})
	if channel == nil {
		t.Errorf("Expected nil channel, got %v", channel)
	}
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	select {
	case result := <-channel:
		status, ok := result.(*kubeapi.Status)
		if !ok {
			t.Errorf("Expected status type, got: %#v", result)
		}
		if status.Status != "failure" || status.Message != "foo" {
			t.Errorf("Expected failure status, got %#V", status)
		}
	case <-time.After(50 * time.Millisecond):
		t.Errorf("Timed out waiting for result")
	default:
	}
}
func TestCreateImageRepositoryMappingBadObject(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	channel, err := storage.Create("bad object")
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil || strings.Index(err.Error(), "not an image repository mapping") == -1 {
		t.Errorf("Expected 'not an image repository mapping' error, got %#v", err)
	}
}
func TestUpdateImageRepositoryMapping(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	channel, err := storage.Update("repo1")
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil || strings.Index(err.Error(), "not supported") == -1 {
		t.Errorf("Expected 'not supported' error, got %#v", err)
	}
}
func TestListImageRepositoryMappings(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	list, err := storage.List(labels.Everything())
	if list != nil {
		t.Errorf("Unexpected non-nil list %#v", list)
	}
	if err == nil || strings.Index(err.Error(), "not supported") == -1 {
		t.Errorf("Expected 'not supported' error, got %#v", err)
	}
}
func TestGetImageRepositoryMapping(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	obj, err := storage.Get("foo")
	if obj != nil {
		t.Errorf("Unexpected non-nil object %#v", obj)
	}
	if err == nil || strings.Index(err.Error(), "not supported") == -1 {
		t.Errorf("Expected 'not supported' error, got %#v", err)
	}
}
Exemple #11
0
func TestGetImageError(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Err = fmt.Errorf("bad")
	storage := ImageStorage{registry: mockRegistry}

	image, err := storage.Get("foo")
	if image != nil {
		t.Errorf("Unexpected non-nil image: %#v", image)
	}
	if err != mockRegistry.Err {
		t.Errorf("Expected %#v, got %#v", mockRegistry.Err, err)
	}
}
Exemple #12
0
func TestListImagesError(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Err = fmt.Errorf("test error")

	storage := ImageStorage{
		registry: mockRegistry,
	}

	images, err := storage.List(nil)
	if err != mockRegistry.Err {
		t.Errorf("Expected %#v, Got %#v", mockRegistry.Err, err)
	}

	if images != nil {
		t.Errorf("Unexpected non-nil images list: %#v", images)
	}
}
Exemple #13
0
func TestListImagesEmptyList(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Images = &api.ImageList{
		Items: []api.Image{},
	}

	storage := ImageStorage{
		registry: mockRegistry,
	}

	images, err := storage.List(labels.Everything())
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	if len(images.(*api.ImageList).Items) != 0 {
		t.Errorf("Unexpected non-zero images list: %#v", images)
	}
}
Exemple #14
0
func TestGetImageOK(t *testing.T) {
	mockRegistry := imagetest.NewImageRegistry()
	mockRegistry.Image = &api.Image{
		JSONBase:             kubeapi.JSONBase{ID: "foo"},
		DockerImageReference: "openshift/ruby-19-centos",
	}
	storage := ImageStorage{registry: mockRegistry}

	image, err := storage.Get("foo")
	if image == nil {
		t.Error("Unexpected nil image")
	}
	if err != nil {
		t.Errorf("Unexpected non-nil error", err)
	}
	if image.(*api.Image).ID != "foo" {
		t.Errorf("Unexpected image: %#v", image)
	}
}
func TestCreateImageRepositoryMapping(t *testing.T) {
	imageRegistry := imagetest.NewImageRegistry()
	imageRepositoryRegistry := imagetest.NewImageRepositoryRegistry()
	imageRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "repo1",
				},
				DockerImageRepository: "localhost:5000/someproject/somerepo",
			},
		},
	}
	storage := &ImageRepositoryMappingStorage{imageRegistry, imageRepositoryRegistry}

	mapping := api.ImageRepositoryMapping{
		DockerImageRepository: "localhost:5000/someproject/somerepo",
		Image: api.Image{
			JSONBase: kubeapi.JSONBase{
				ID: "imageID1",
			},
			DockerImageReference: "localhost:5000/someproject/somerepo:imageID1",
			Metadata: docker.Image{
				Config: &docker.Config{
					Cmd:          []string{"ls", "/"},
					Env:          []string{"a=1"},
					ExposedPorts: map[docker.Port]struct{}{"1234/tcp": {}},
					Memory:       1234,
					CpuShares:    99,
					WorkingDir:   "/workingDir",
				},
			},
		},
		Tag: "latest",
	}
	ch, err := storage.Create(&mapping)
	if err != nil {
		t.Errorf("Unexpected error creating mapping: %#v", err)
	}

	out := <-ch
	t.Logf("out = '%#v'", out)

	image, err := imageRegistry.GetImage("imageID1")
	if err != nil {
		t.Errorf("Unexpected error retrieving image: %#v", err)
	}
	if e, a := mapping.Image.DockerImageReference, image.DockerImageReference; e != a {
		t.Errorf("Expected %s, got %s", e, a)
	}
	if !reflect.DeepEqual(mapping.Image.Metadata, image.Metadata) {
		t.Errorf("Expected %#v, got %#v", mapping.Image, image)
	}

	repo, err := imageRepositoryRegistry.GetImageRepository("repo1")
	if err != nil {
		t.Errorf("Unexpected non-nil err: %#v", err)
	}
	if e, a := "imageID1", repo.Tags["latest"]; e != a {
		t.Errorf("Expected %s, got %s", e, a)
	}
}