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 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 #3
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 #4
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)
	}
}