github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/internal/outlet/switch_test.go (about) 1 package outlet 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/martinohmann/rfoutlet/pkg/gpio" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestSwitch(t *testing.T) { 12 s := NewSwitch(gpio.NewDiscardingTransmitter()) 13 o := &Outlet{State: StateOn, Protocol: 1} 14 15 assert.NoError(t, s.Switch(o, StateOff)) 16 assert.Equal(t, StateOff, o.GetState()) 17 18 assert.NoError(t, s.Switch(o, StateOn)) 19 assert.Equal(t, StateOn, o.GetState()) 20 } 21 22 func TestFakeSwitch(t *testing.T) { 23 s := &FakeSwitch{} 24 o := &Outlet{State: StateOn} 25 26 assert.NoError(t, s.Switch(o, StateOff)) 27 assert.Equal(t, StateOff, o.GetState()) 28 29 s = &FakeSwitch{Err: errors.New("whoops")} 30 31 assert.Error(t, s.Switch(o, StateOn)) 32 assert.Equal(t, StateOff, o.GetState()) 33 }