Skip to content

Commit

Permalink
Add tests for volume and mute
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 11, 2024
1 parent f866b86 commit 15fcc5a
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion remote/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Control) GetVolumeMute() (bool, error) {
return false, err
}

resp := [4]byte{}
resp := [5]byte{}
_, err = c.conn.Read(resp[:])
if err != nil {
return false, err
Expand Down
104 changes: 104 additions & 0 deletions remote/volume_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package remote

import (
"testing"
)

func TestSetVolume(t *testing.T) {
control, mock := newControlMock()

err := control.SetVolume(101)
if err == nil {
t.Fail()
}

err = control.SetVolume(0)
if err != nil || mock.writeBuf.String() != "-v.0\r" {
t.Fail()
}

mock.Close()

err = control.SetVolume(100)
if err != nil || mock.writeBuf.String() != "-v.100\r" {
t.Fail()
}
}

func TestVolumeUp(t *testing.T) {
control, mock := newControlMock()

err := control.VolumeUp()
if err != nil || mock.writeBuf.String() != "-v.u\r" {
t.Fail()
}
}

func TestVolumeDown(t *testing.T) {
control, mock := newControlMock()

err := control.VolumeDown()
if err != nil || mock.writeBuf.String() != "-v.d\r" {
t.Fail()
}
}

func TestGetVolume(t *testing.T) {
control, mock := newControlMock()

control.SetVolume(0)
mock.FlushToReader()

volume, err := control.GetVolume()
if err != nil || volume != 0 {
t.Fail()
}

mock.Close()

control.SetVolume(100)
mock.FlushToReader()

volume, err = control.GetVolume()
if err != nil || volume != 100 {
t.Fail()
}
}

func TestSetVolumeMute(t *testing.T) {
control, mock := newControlMock()

err := control.SetVolumeMute(false)
if err != nil || mock.writeBuf.String() != "-m.0\r" {
t.Fail()
}

mock.Close()

err = control.SetVolumeMute(true)
if err != nil || mock.writeBuf.String() != "-m.1\r" {
t.Fail()
}
}

func TestGetVolumeMute(t *testing.T) {
control, mock := newControlMock()

control.SetVolumeMute(false)
mock.FlushToReader()

muted, err := control.GetVolumeMute()
if err != nil || muted {
t.Fail()
}

mock.Close()

control.SetVolumeMute(true)
mock.FlushToReader()

muted, err = control.GetVolumeMute()
if err != nil || !muted {
t.Fail()
}
}

0 comments on commit 15fcc5a

Please sign in to comment.