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

View File

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

View File

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

View File

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