[refactor] Move mode in generic types module

This commit is contained in:
Cyrille Nofficial 2019-12-21 18:13:58 +01:00
parent a0dedb056b
commit 37e90572fd
4 changed files with 11 additions and 12 deletions

View File

@ -2,7 +2,7 @@ package mqttdevice
import (
"fmt"
"github.com/cyrilix/robocar-base/mode"
"github.com/cyrilix/robocar-base/types"
MQTT "github.com/eclipse/paho.mqtt.golang"
"io"
"log"
@ -128,12 +128,12 @@ func (m *MqttValue) Float64Value() (float64, error) {
func (m *MqttValue) StringValue() (string, error) {
return string(*m), nil
}
func (m *MqttValue) DriveModeValue() (mode.DriveMode, error) {
func (m *MqttValue) DriveModeValue() (types.DriveMode, error) {
val, err := m.IntValue()
if err != nil {
return mode.DriveModeInvalid, err
return types.DriveModeInvalid, err
}
return mode.DriveMode(val), nil
return types.DriveMode(val), nil
}
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
return *m, nil

View File

@ -1,7 +1,7 @@
package mqttdevice
import (
"github.com/cyrilix/robocar-base/mode"
"github.com/cyrilix/robocar-base/types"
"github.com/cyrilix/robocar-base/testtools/docker"
mqtt "github.com/eclipse/paho.mqtt.golang"
"testing"
@ -192,11 +192,11 @@ func TestMqttValue_StringValue(t *testing.T) {
func TestMqttValue_DriveModeValue(t *testing.T) {
cases := []struct {
value MqttValue
expected mode.DriveMode
expected types.DriveMode
}{
{NewMqttValue(mode.DriveModeUser), mode.DriveModeUser},
{NewMqttValue(mode.DriveModePilot), mode.DriveModePilot},
{NewMqttValue(mode.DriveModeInvalid), mode.DriveModeInvalid},
{NewMqttValue(types.DriveModeUser), types.DriveModeUser},
{NewMqttValue(types.DriveModePilot), types.DriveModePilot},
{NewMqttValue(types.DriveModeInvalid), types.DriveModeInvalid},
}
for _, c := range cases {
val, err := c.value.DriveModeValue()

View File

@ -1,4 +1,4 @@
package mode
package types
import (
"log"
@ -32,6 +32,5 @@ func ParseString(val string) DriveMode {
default:
log.Printf("invalid DriveMode: %v", val)
return DriveModeInvalid
}
}

View File

@ -1,4 +1,4 @@
package mode
package types
import "testing"