File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,21 @@ package camera
22
33import (
44 "encoding/base64"
5+ "strings"
56 "testing"
67
78 "github.com/AlexxIT/go2rtc/pkg/hap"
89 "github.com/stretchr/testify/require"
910)
1011
12+ func TestNilCharacter (t * testing.T ) {
13+ var res SetupEndpoints
14+ char := & hap.Character {}
15+ err := char .ReadTLV8 (& res )
16+ require .NotNil (t , err )
17+ require .NotNil (t , strings .Contains (err .Error (), "can't read value" ))
18+ }
19+
1120type testTLV8 struct {
1221 name string
1322 value string
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package hap
33import (
44 "bytes"
55 "encoding/json"
6+ "fmt"
67 "io"
78 "net/http"
89
@@ -126,11 +127,17 @@ func (c *Character) Write(v any) (err error) {
126127
127128// ReadTLV8 value to right struct
128129func (c * Character ) ReadTLV8 (v any ) (err error ) {
129- return tlv8 .UnmarshalBase64 (c .Value .(string ), v )
130+ if s , ok := c .Value .(string ); ok {
131+ return tlv8 .UnmarshalBase64 (s , v )
132+ }
133+ return fmt .Errorf ("hap: can't read value: %v" , v )
130134}
131135
132- func (c * Character ) ReadBool () bool {
133- return c .Value .(bool )
136+ func (c * Character ) ReadBool () (bool , error ) {
137+ if v , ok := c .Value .(bool ); ok {
138+ return v , nil
139+ }
140+ return false , fmt .Errorf ("hap: can't read value: %v" , c .Value )
134141}
135142
136143func (c * Character ) String () string {
You can’t perform that action at this time.
0 commit comments