Beispiel #1
0
func TestListImageRepositoriesPopulatedList(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "foo",
				},
			},
			{
				JSONBase: kubeapi.JSONBase{
					ID: "bar",
				},
			},
		},
	}

	storage := REST{
		registry: mockRepositoryRegistry,
	}

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

	imageRepositories := list.(*api.ImageRepositoryList)

	if e, a := 2, len(imageRepositories.Items); e != a {
		t.Errorf("Expected %v, got %v", e, a)
	}
}
Beispiel #2
0
func TestCreateImageRepositoryMappingFindError(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	imageRepositoryRegistry.Err = fmt.Errorf("123")
	storage := &REST{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 {
		t.Fatal("Unexpected nil err")
	}
	if err.Error() != "123" {
		t.Errorf("Expected 'unable to locate' error, got %#v", err)
	}
}
Beispiel #3
0
func TestGetImageRepositoryError(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.Err = fmt.Errorf("test error")
	storage := REST{registry: mockRepositoryRegistry}

	image, err := storage.Get("image1")
	if image != nil {
		t.Errorf("Unexpected non-nil image: %#v", image)
	}
	if err != mockRepositoryRegistry.Err {
		t.Errorf("Expected %#v, got %#v", mockRepositoryRegistry.Err, err)
	}
}
Beispiel #4
0
func TestCreateImageRepositoryMappingBadObject(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := &REST{imageRegistry, imageRepositoryRegistry}

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

	channel, err := storage.Update("repo1")
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil {
		t.Fatal("Unexpected nil err")
	}
	if strings.Index(err.Error(), "ImageRepositoryMappings may not be changed.") == -1 {
		t.Errorf("Expected 'may not be changed' error, got %#v", err)
	}
}
Beispiel #6
0
func TestDeleteImageRepositoryMapping(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := &REST{imageRegistry, imageRepositoryRegistry}

	channel, err := storage.Delete("repo1")
	if channel != nil {
		t.Errorf("Unexpected non-nil channel %#v", channel)
	}
	if err == nil {
		t.Fatal("Unexpected nil err")
	}
	if !errors.IsNotFound(err) {
		t.Errorf("Expected 'not found' error, got %#v", err)
	}
}
Beispiel #7
0
func TestListImageRepositoryMappings(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := &REST{imageRegistry, imageRepositoryRegistry}

	list, err := storage.List(labels.Everything())
	if list != nil {
		t.Errorf("Unexpected non-nil list %#v", list)
	}
	if err == nil {
		t.Fatal("Unexpected nil err")
	}
	if !errors.IsNotFound(err) {
		t.Errorf("Expected 'not found' error, got %#v", err)
	}
}
Beispiel #8
0
func TestGetImageRepositoryMapping(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := &REST{imageRegistry, imageRepositoryRegistry}

	obj, err := storage.Get("foo")
	if obj != nil {
		t.Errorf("Unexpected non-nil object %#v", obj)
	}
	if err == nil {
		t.Fatal("Unexpected nil err")
	}
	if !errors.IsNotFound(err) {
		t.Errorf("Expected 'not found' error, got %#v", err)
	}
}
Beispiel #9
0
func TestListImageRepositoriesError(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.Err = fmt.Errorf("test error")

	storage := REST{
		registry: mockRepositoryRegistry,
	}

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

	if imageRepositories != nil {
		t.Errorf("Unexpected non-nil imageRepositories list: %#v", imageRepositories)
	}
}
Beispiel #10
0
func TestDeleteImageRepository(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := REST{registry: mockRepositoryRegistry}

	channel, err := storage.Delete("foo")
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}
	result := <-channel
	status, ok := result.(*kubeapi.Status)
	if !ok {
		t.Errorf("Expected status, got %#v", result)
	}
	if status.Status != "success" {
		t.Errorf("Expected status=success, got %#v", status)
	}
}
Beispiel #11
0
func TestCreateRegistryErrorSaving(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.Err = fmt.Errorf("foo")
	storage := REST{registry: mockRepositoryRegistry}

	channel, err := storage.Create(&api.ImageRepository{})
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}
	result := <-channel
	status, ok := result.(*kubeapi.Status)
	if !ok {
		t.Errorf("Expected status, got %#v", result)
	}
	if status.Status != "failure" || status.Message != "foo" {
		t.Errorf("Expected status=failure, message=foo, got %#v", status)
	}
}
Beispiel #12
0
func TestListImageRepositoriesEmptyList(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{},
	}

	storage := REST{
		registry: mockRepositoryRegistry,
	}

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

	if len(imageRepositories.(*api.ImageRepositoryList).Items) != 0 {
		t.Errorf("Unexpected non-zero imageRepositories list: %#v", imageRepositories)
	}
}
Beispiel #13
0
func TestGetImageRepositoryOK(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	mockRepositoryRegistry.ImageRepository = &api.ImageRepository{
		JSONBase:              kubeapi.JSONBase{ID: "foo"},
		DockerImageRepository: "openshift/ruby-19-centos",
	}
	storage := REST{registry: mockRepositoryRegistry}

	repo, err := storage.Get("foo")
	if repo == nil {
		t.Errorf("Unexpected nil repo: %#v", repo)
	}
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}
	if e, a := mockRepositoryRegistry.ImageRepository, repo; !reflect.DeepEqual(e, a) {
		t.Errorf("Expected %#v, got %#v", e, a)
	}
}
Beispiel #14
0
func TestUpdateImageRepositoryOK(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := REST{registry: mockRepositoryRegistry}

	channel, err := storage.Update(&api.ImageRepository{
		JSONBase: kubeapi.JSONBase{ID: "bar"},
	})
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}
	result := <-channel
	repo, ok := result.(*api.ImageRepository)
	if !ok {
		t.Errorf("Expected image repository, got %#v", result)
	}
	if repo.ID != "bar" {
		t.Errorf("Unexpected repo returned: %#v", repo)
	}
}
Beispiel #15
0
func TestCreateImageRepositoryOK(t *testing.T) {
	mockRepositoryRegistry := test.NewImageRepositoryRegistry()
	storage := REST{registry: mockRepositoryRegistry}

	channel, err := storage.Create(&api.ImageRepository{})
	if err != nil {
		t.Errorf("Unexpected non-nil error: %#v", err)
	}

	result := <-channel
	repo, ok := result.(*api.ImageRepository)
	if !ok {
		t.Errorf("Unexpected result: %#v", result)
	}
	if len(repo.ID) == 0 {
		t.Errorf("Expected repo's ID to be set: %#v", repo)
	}
	if repo.CreationTimestamp.IsZero() {
		t.Error("Unexpected zero CreationTimestamp")
	}
}
Beispiel #16
0
func TestCreateImageRepositoryMappingNotFound(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	imageRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "repo1",
				},
				DockerImageRepository: "localhost:5000/test/repo",
			},
		},
	}
	storage := &REST{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 {
		t.Fatal("Unexpected nil err")
	}
	if !errors.IsInvalid(err) {
		t.Fatalf("Expected 'invalid' err, got: %#v", err)
	}
}
Beispiel #17
0
func TestCreateImageRepositoryMapping(t *testing.T) {
	imageRegistry := test.NewImageRegistry()
	imageRepositoryRegistry := test.NewImageRepositoryRegistry()
	imageRepositoryRegistry.ImageRepositories = &api.ImageRepositoryList{
		Items: []api.ImageRepository{
			{
				JSONBase: kubeapi.JSONBase{
					ID: "repo1",
				},
				DockerImageRepository: "localhost:5000/someproject/somerepo",
			},
		},
	}
	storage := &REST{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)
	}
}