huetest

package
v0.0.0-...-14fd71e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2016 License: MIT Imports: 2 Imported by: 0

README

go-hue/huetest

A stub implementation of the hue.API interface for testing purposes. This package allows you to easily stub out calls to the server.

Please see godoc.org for detailed API description.

Example

See the examples directory for running code using this package. Below is an inline excerpt from that directory.

package example

import (
	"github.com/bcurren/go-hue"
	"github.com/bcurren/go-hue/huetest"
	"testing"
)

func Test_GetLightAttributesSuccess(t *testing.T) {
	stubAPI := &huetest.StubAPI{}
	stubAPI.GetLightAttributesReturn = &hue.LightAttributes{}
	stubAPI.GetLightAttributesError = nil

	attrs, err := stubAPI.GetLightAttributes("light1")
	if err != stubAPI.GetLightAttributesError {
		t.Fatal("err is GetLightAttributesError so it must be nil")
	}
	if attrs != stubAPI.GetLightAttributesReturn {
		t.Fatal("attrs is GetLightAttributesReturn so it must be equal")
	}

	if "light1" != stubAPI.GetLightAttributesParamLightId {
		t.Fatal("GetLightAttributesParamLightId is set to light id parameter so it must be equal")
	}
}

Documentation

Overview

Package with a Stub API that conforms to the hue.API interface for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StubAPI

type StubAPI struct {
	// Stub GetLights()
	GetLightsReturn []hue.Light
	GetLightsError  error

	// Stub GetNewLights()
	GetNewLightsReturn     []hue.Light
	GetNewLightsReturnTime time.Time
	GetNewLightsError      error

	// Stub SearchForNewLights()
	SearchForNewLightsError error

	// Stub GetLightAttributes()
	GetLightAttributesReturn       *hue.LightAttributes
	GetLightAttributesError        error
	GetLightAttributesParamLightId string

	// Stub SetLightName()
	SetLightNameError        error
	SetLightNameParamLightId string
	SetLightNameParamName    string

	// Stub SetLightState()
	SetLightStateError           error
	SetLightStateParamLightId    string
	SetLightStateParamLightState *hue.LightState

	// Stub SetGroupState()
	SetGroupStateError           error
	SetGroupStateParamGroupId    string
	SetGroupStateParamLightState *hue.LightState
}

StubAPI contains the stub return values for all functions in the hue.API interface.

Here is an example of how to use this struct:

var stub huetest.StubAPI stub.GetLightsError = errors.NewError("This is an error")

lights, err := stub.GetLights()

if err.Error() != "This is an error" {
	fmt.Println("Stub is not working")
}

func (*StubAPI) GetLightAttributes

func (s *StubAPI) GetLightAttributes(lightId string) (*hue.LightAttributes, error)

Stub version of GetLightAttributes. This function just returns GetLightAttributesReturn and GetLightAttributesError in StubAPI struct. It will also set GetLightAttributesParamLightId in StubAPI to the value of the lightId parameter.

func (*StubAPI) GetLights

func (s *StubAPI) GetLights() ([]hue.Light, error)

Stub version of GetLights. This function just returns GetLightsReturn and GetLightsError in StubAPI struct.

func (*StubAPI) GetNewLights

func (s *StubAPI) GetNewLights() ([]hue.Light, time.Time, error)

Stub version of GetNewLights. This function just returns GetNewLightsReturn, GetNewLightsReturnTime and GetNewLightsError in StubAPI struct.

func (*StubAPI) SearchForNewLights

func (s *StubAPI) SearchForNewLights() error

Stub version of SearchForNewLights. This function just returns SearchForNewLightsError in StubAPI struct.

func (*StubAPI) SetGroupState

func (s *StubAPI) SetGroupState(lightId string, state *hue.LightState) error

Stub version of SetGroupState. This function just returns SetGroupStateError in StubAPI struct. It will also set SetGroupStateGroupId to the value of groupID parameter and SetGroupStateParamLightState to the value of the state parameter.

func (*StubAPI) SetLightName

func (s *StubAPI) SetLightName(lightId string, name string) error

Stub version of SetLightName. This function just returns SetLightNameError in StubAPI struct. It will also set SetLightNameParamLightId to the value of lightId parameter and SetLightNameParamName to the value of the name parameter.

func (*StubAPI) SetLightState

func (s *StubAPI) SetLightState(lightId string, state *hue.LightState) error

Stub version of SetLightState. This function just returns SetLightStateError in StubAPI struct. It will also set SetLightStateParamLightId to the value of lightId parameter and SetLightStateParamLightState to the value of the state parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL