Skip to content

Commit

Permalink
Add basic tests for power set commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 10, 2024
1 parent 30f11cb commit f12cfb7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions remote/commands_test.go
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions remote/power_test.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit f12cfb7

Please sign in to comment.