Exemplo n.º 1
0
func TestCreatePod(t *testing.T) {
	mockRegistry := registrytest.PodRegistry{
		Pod: &api.Pod{
			JSONBase: api.JSONBase{ID: "foo"},
			CurrentState: api.PodState{
				Host: "machine",
			},
		},
	}
	storage := RegistryStorage{
		registry:      &mockRegistry,
		podPollPeriod: time.Millisecond * 100,
		scheduler:     scheduler.MakeRoundRobinScheduler(),
		minionLister:  minion.NewRegistry([]string{"machine"}),
	}
	desiredState := api.PodState{
		Manifest: api.ContainerManifest{
			Version: "v1beta1",
		},
	}
	pod := &api.Pod{
		JSONBase:     api.JSONBase{ID: "foo"},
		DesiredState: desiredState,
	}
	channel, err := storage.Create(pod)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	select {
	case <-time.After(time.Millisecond * 100):
		// Do nothing, this is expected.
	case <-channel:
		t.Error("Unexpected read from async channel")
	}
	mockRegistry.UpdatePod(api.Pod{
		JSONBase: api.JSONBase{ID: "foo"},
		CurrentState: api.PodState{
			Status: api.PodRunning,
		},
	})
	select {
	case <-time.After(time.Second * 1):
		t.Error("Unexpected timeout")
	case <-channel:
		// Do nothing, this is expected.
	}
}
Exemplo n.º 2
0
func TestCreateController(t *testing.T) {
	mockRegistry := registrytest.ControllerRegistry{}
	mockPodRegistry := registrytest.PodRegistry{
		Pods: []api.Pod{
			{
				JSONBase: api.JSONBase{ID: "foo"},
				Labels:   map[string]string{"a": "b"},
			},
		},
	}
	storage := RegistryStorage{
		registry:    &mockRegistry,
		podRegistry: &mockPodRegistry,
		pollPeriod:  time.Millisecond * 1,
	}
	controller := &api.ReplicationController{
		JSONBase: api.JSONBase{ID: "test"},
		DesiredState: api.ReplicationControllerState{
			Replicas:        2,
			ReplicaSelector: map[string]string{"a": "b"},
			PodTemplate:     validPodTemplate,
		},
	}
	channel, err := storage.Create(controller)
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	select {
	case <-time.After(time.Millisecond * 100):
		// Do nothing, this is expected.
	case <-channel:
		t.Error("Unexpected read from async channel")
	}

	mockPodRegistry.Lock()
	mockPodRegistry.Pods = []api.Pod{
		{
			JSONBase: api.JSONBase{ID: "foo"},
			Labels:   map[string]string{"a": "b"},
		},
		{
			JSONBase: api.JSONBase{ID: "bar"},
			Labels:   map[string]string{"a": "b"},
		},
	}
	mockPodRegistry.Unlock()

	select {
	case <-time.After(time.Second * 1):
		t.Error("Unexpected timeout")
	case <-channel:
		// Do nothing, this is expected
	}
}