Пример #1
0
func TestControllerStorageValidatesUpdate(t *testing.T) {
	mockRegistry := registrytest.ControllerRegistry{}
	storage := RegistryStorage{
		registry:    &mockRegistry,
		podRegistry: nil,
		pollPeriod:  time.Millisecond * 1,
	}
	failureCases := map[string]api.ReplicationController{
		"empty ID": {
			JSONBase: api.JSONBase{ID: ""},
			DesiredState: api.ReplicationControllerState{
				ReplicaSelector: map[string]string{"bar": "baz"},
			},
		},
		"empty selector": {
			JSONBase:     api.JSONBase{ID: "abc"},
			DesiredState: api.ReplicationControllerState{},
		},
	}
	for _, failureCase := range failureCases {
		c, err := storage.Update(&failureCase)
		if c != nil {
			t.Errorf("Expected nil channel")
		}
		if !apiserver.IsInvalid(err) {
			t.Errorf("Expected to get an invalid resource error, got %v", err)
		}
	}
}
Пример #2
0
func TestServiceStorageValidatesCreate(t *testing.T) {
	registry := registrytest.NewServiceRegistry()
	storage := NewRegistryStorage(registry, nil, nil)
	failureCases := map[string]api.Service{
		"empty ID": {
			Port:     6502,
			JSONBase: api.JSONBase{ID: ""},
			Selector: map[string]string{"bar": "baz"},
		},
		"empty selector": {
			JSONBase: api.JSONBase{ID: "foo"},
			Selector: map[string]string{},
		},
	}
	for _, failureCase := range failureCases {
		c, err := storage.Create(&failureCase)
		if c != nil {
			t.Errorf("Expected nil channel")
		}
		if !apiserver.IsInvalid(err) {
			t.Errorf("Expected to get an invalid resource error, got %v", err)
		}

	}
}
Пример #3
0
func TestPodStorageValidatesUpdate(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := RegistryStorage{
		registry: podRegistry,
	}
	pod := &api.Pod{}
	c, err := storage.Update(pod)
	if c != nil {
		t.Errorf("Expected nil channel")
	}
	if !apiserver.IsInvalid(err) {
		t.Errorf("Expected to get an invalid resource error, got %v", err)
	}
}