GetFloat, SetFloat now return error type on error

GetString, SetString now return error type on error

SendText now returns error type on error

remote_test updated.
This commit is contained in:
onyx-and-iris 2022-09-18 05:35:04 +01:00
parent e16a51c0da
commit 00f66e8f9e
2 changed files with 31 additions and 16 deletions

View File

@ -83,36 +83,48 @@ func (r *Remote) Sync() {
}
// Gets a float parameter value
func (r *Remote) GetFloat(name string) float64 {
func (r *Remote) GetFloat(name string) (float64, error) {
val, err := getParameterFloat(name)
if err != nil {
fmt.Println(err)
return 0, err
}
return val
return val, nil
}
// Sets a float paramter value
func (r *Remote) SetFloat(name string, value float64) {
setParameterFloat(name, value)
func (r *Remote) SetFloat(name string, value float64) error {
err := setParameterFloat(name, value)
if err != nil {
return err
}
return nil
}
// Gets a string parameter value
func (r *Remote) GetString(name string) string {
func (r *Remote) GetString(name string) (string, error) {
val, err := getParameterString(name)
if err != nil {
fmt.Println(err)
return "", err
}
return val
return val, nil
}
// Sets a string paramter value
func (r *Remote) SetString(name, value string) {
setParameterString(name, value)
func (r *Remote) SetString(name, value string) error {
err := setParameterString(name, value)
if err != nil {
return err
}
return nil
}
// SendText sets multiple parameters by script
func (r *Remote) SendText(script string) {
setParametersMulti(script)
func (r *Remote) SendText(script string) error {
err := setParametersMulti(script)
if err != nil {
return err
}
return nil
}
// Register forwards the register method to Pooler

View File

@ -87,18 +87,21 @@ func TestGetPotatoRemote(t *testing.T) {
func TestSetAndGetFloatParameter(t *testing.T) {
//t.Skip("skipping test")
var param = "strip[0].mute"
var exp = float64(1)
vm.SetFloat(param, 1)
t.Run("Should get a float parameter", func(t *testing.T) {
assert.Equal(t, float64(1), vm.GetFloat(param))
val, _ := vm.GetFloat(param)
assert.Equal(t, exp, val)
})
}
func TestSetAndGetStringParameter(t *testing.T) {
//t.Skip("skipping test")
var param = "strip[0].label"
var val = "test0"
vm.SetString(param, val)
var exp = "test0"
vm.SetString(param, exp)
t.Run("Should get a string parameter", func(t *testing.T) {
assert.Equal(t, val, vm.GetString(param))
val, _ := vm.GetString(param)
assert.Equal(t, exp, val)
})
}