Example #1
0
func TestCreateNoClientItems(t *testing.T) {
	items := []runtime.Object{}

	items = append(items, &api.Pod{
		TypeMeta:   api.TypeMeta{APIVersion: "v1beta1", Kind: "Pod"},
		ObjectMeta: api.ObjectMeta{Name: "test-pod"},
	})

	typer, mapper := getTyperAndMapper()
	_, s := getFakeClient(t, []string{"/api/v1beta1/pods", "/api/v1beta1/services"})

	noClientFunc := func(mapping *meta.RESTMapping) (*client.RESTClient, error) {
		return nil, fmt.Errorf("no client")
	}

	errs := CreateObjects(typer, mapper, noClientFunc, items)
	s.Close()

	if len(errs) == 0 {
		t.Errorf("Expected invalid value error for client")
	}

	e := errs[0].(errors.ValidationError)
	if errors.ValueOf(e.Type) != "unsupported value" {
		t.Errorf("Expected ValidationErrorTypeUnsupported error, got %#v", e)
	}

	if e.Field != "Config.item[0].client" {
		t.Errorf("Expected 'Config.item[0].client' as error field, got '%#v'", e.Field)
	}
}
Example #2
0
func TestCreateNoNameItem(t *testing.T) {
	items := []runtime.Object{}

	items = append(items, &api.Service{
		TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Kind: "Service"},
	})

	typer, mapper := getTyperAndMapper()
	client, s := getFakeClient(t, []string{"/api/v1beta1/services"})

	errs := CreateObjects(typer, mapper, client, items)
	s.Close()

	if len(errs) == 0 {
		t.Errorf("Expected required value error for missing name")
	}

	e := errs[0].(errors.ValidationError)
	if errors.ValueOf(e.Type) != "required value" {
		t.Errorf("Expected ValidationErrorTypeRequired error, got %#v", e)
	}

	if e.Field != "Config.item[0].name" {
		t.Errorf("Expected 'Config.item[0].name' as error field, got '%#v'", e.Field)
	}
}
Example #3
0
func TestCreateInvalidItem(t *testing.T) {
	items := []runtime.Object{
		&InvalidItem{},
	}

	typer, mapper := getTyperAndMapper()
	client, s := getFakeClient(t, []string{})

	errs := CreateObjects(typer, mapper, client, items)
	s.Close()

	if len(errs) == 0 {
		t.Errorf("Expected invalid value error for kind")
	}

	e := errs[0].(errors.ValidationError)
	if errors.ValueOf(e.Type) != "invalid value" {
		t.Errorf("Expected ValidationErrorTypeInvalid error, got %#v", e)
	}

	if e.Field != "Config.item[0].kind" {
		t.Errorf("Expected 'Config.item[0].kind' as error field, got '%#v'", e.Field)
	}
}