From f12cfb737edc35dd7c878d73e3b57e2be9763020 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Tue, 10 Dec 2024 23:50:40 +0100 Subject: [PATCH] Add basic tests for power set commands --- remote/commands_test.go | 18 ++++++++++++++++++ remote/power_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 remote/commands_test.go create mode 100644 remote/power_test.go diff --git a/remote/commands_test.go b/remote/commands_test.go new file mode 100644 index 0000000..bb6ab70 --- /dev/null +++ b/remote/commands_test.go @@ -0,0 +1,18 @@ +package remote + +import "bytes" + +type testConnAdapter struct { + bytes.Buffer +} + +func (t *testConnAdapter) Close() error { + return nil +} + +func newControlTester() (*Control, *testConnAdapter) { + control := &Control{} + adapter := &testConnAdapter{} + control.conn = adapter + return control, adapter +} diff --git a/remote/power_test.go b/remote/power_test.go new file mode 100644 index 0000000..b1cee30 --- /dev/null +++ b/remote/power_test.go @@ -0,0 +1,29 @@ +package remote + +import "testing" + +func TestSetPower(t *testing.T) { + control, adapter := newControlTester() + + control.SetPower(true) + if adapter.String() != "-p.1\r" { + t.Fail() + } + adapter.Reset() + + control.SetPower(false) + if adapter.String() != "-p.0\r" { + t.Fail() + } + adapter.Reset() +} + +func TestTogglePower(t *testing.T) { + control, adapter := newControlTester() + + control.TogglePower() + if adapter.String() != "-p.t\r" { + t.Fail() + } + adapter.Reset() +}