Exemple #1
0
func verifyAction(t *testing.T, expected []request, action actions.Action) {
	clock := &tasks.ClockForTesting{kNow}
	context := &setterForTesting{clock: clock, now: kNow}
	tasks.RunForTesting(action.AsTask(context, nil), clock)
	if !reflect.DeepEqual(expected, context.requests) {
		t.Errorf("Expected %v, got %v", expected, context.requests)
	}
}
Exemple #2
0
func TestRecurringError(t *testing.T) {
	timeTask := &fakeTask{err: kSomeError}
	r := recurring.AtInterval(kNow, time.Hour)
	tasks.RunForTesting(
		tasks.RecurringTask(timeTask, r), &tasks.ClockForTesting{kNow})
	verifyTimes(
		t, timeTask.timeStamps,
		kNow.Add(time.Hour))
}
Exemple #3
0
func TestRecurringOverrun(t *testing.T) {
	timeTask := &fakeTask{runDuration: time.Hour}
	r := recurring.Until(
		recurring.AtInterval(kNow, time.Hour), kNow.Add(5*time.Hour))
	tasks.RunForTesting(
		tasks.RecurringTask(timeTask, r), &tasks.ClockForTesting{kNow})
	verifyTimes(
		t, timeTask.timeStamps, kNow.Add(time.Hour), kNow.Add(3*time.Hour))
}
Exemple #4
0
func TestRecurringCloseStream(t *testing.T) {
	task := tasks.NilTask()
	r := &testForClose{}
	tasks.RunForTesting(
		tasks.RecurringTask(task, r), &tasks.ClockForTesting{kNow})
	if !r.closeCalled {
		t.Error("Expected close to be called.")
	}
}
Exemple #5
0
func TestNoZeroLightId(t *testing.T) {
	action := actions.Action{On: true}
	clock := &tasks.ClockForTesting{kNow}
	context := &setterForTesting{clock: clock, now: kNow}
	err := tasks.RunForTesting(action.AsTask(context, []int{1, 0, 2}), clock)
	if out := len(context.requests); out != 1 {
		t.Errorf("Expected one request, got %d", out)
	}
	noSuchLightIdError, isNoSuchLightIdErr := err.(*actions.NoSuchLightIdError)
	if !isNoSuchLightIdErr {
		t.Error("Expected a NoSuchLightIdError.")
		return
	}
	if out := noSuchLightIdError.LightId; out != 0 {
		t.Errorf("Expected 0, got %d", out)
	}
	if out := noSuchLightIdError.Error(); out != "Invalid light id" {
		t.Errorf("Expected 'Invalid light id', got %s", out)
	}
}
Exemple #6
0
func TestNoSuchLightIdError(t *testing.T) {
	action := actions.Action{On: true}
	clock := &tasks.ClockForTesting{kNow}
	context := &setterForTesting{
		err:      gohue.NoSuchResourceError,
		response: ([]byte)("hello"),
		clock:    clock,
		now:      kNow}
	err := tasks.RunForTesting(action.AsTask(context, []int{2, 3}), clock)
	noSuchLightIdError, isNoSuchLightIdErr := err.(*actions.NoSuchLightIdError)
	if !isNoSuchLightIdErr {
		t.Error("Expected a NoSuchLightIdError.")
		return
	}
	if out := noSuchLightIdError.LightId; out != 2 {
		t.Errorf("Expected 2, got %d", out)
	}
	if out := noSuchLightIdError.Error(); out != "hello" {
		t.Errorf("Expected 'hello', got %s", out)
	}
}
Exemple #7
0
func TestError(t *testing.T) {
	action := actions.Action{
		Series: []*actions.Action{
			{Lights: []int{2, 3}, On: true},
			{Sleep: 3000},
			{Off: true}}}
	expected := []request{
		{L: 2, On: maybe.NewBool(true), D: 0}}
	clock := &tasks.ClockForTesting{kNow}
	context := &setterForTesting{
		err: kSomeError, response: ([]byte)("goodbye"), clock: clock, now: kNow}
	err := tasks.RunForTesting(action.AsTask(context, nil), clock)
	if !reflect.DeepEqual(expected, context.requests) {
		t.Errorf("Expected %v, got %v", expected, context.requests)
	}
	_, isNoSuchLightIdError := err.(*actions.NoSuchLightIdError)
	if isNoSuchLightIdError {
		t.Error("Expected not to get NoSuchLightIdError.")
		return
	}
	if out := err.Error(); out != "goodbye" {
		t.Errorf("Expected to get 'goodbye', got %s", out)
	}
}