Fix drive mode parsing

This commit is contained in:
2019-12-18 21:22:09 +01:00
parent 5bab774e44
commit a4c228ed94
862 changed files with 15 additions and 298367 deletions

View File

@ -96,8 +96,6 @@ func NewMqttValue(v interface{}) MqttValue {
return MqttValue(fmt.Sprintf("%0.2f", val))
case int, int8, int16, int32, int64:
return MqttValue(fmt.Sprintf("%d", val))
case mode.DriveMode:
return MqttValue(mode.ToString(val))
case bool:
if val {
return []byte("ON")
@ -130,6 +128,13 @@ func (m *MqttValue) Float64Value() (float64, error) {
func (m *MqttValue) StringValue() (string, error) {
return string(*m), nil
}
func (m *MqttValue) DriveModeValue() (mode.DriveMode, error) {
val, err := m.IntValue()
if err != nil {
return mode.DriveModeInvalid, err
}
return mode.DriveMode(val), nil
}
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
return *m, nil
}

View File

@ -1,43 +1,11 @@
package testtools
import (
"context"
"fmt"
"github.com/cyrilix/robocar-base/mqttdevice"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"sync"
"testing"
)
func MqttContainer(t *testing.T) (context.Context, testcontainers.Container, string) {
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "eclipse-mosquitto",
ExposedPorts: []string{"1883/tcp"},
WaitingFor: wait.ForLog("listen socket on port 1883."),
}
mqttC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
t.Error(err)
}
ip, err := mqttC.Host(ctx)
if err != nil {
t.Error(err)
}
port, err := mqttC.MappedPort(ctx, "1883/tcp")
if err != nil {
t.Error(err)
}
mqttUri := fmt.Sprintf("tcp://%s:%d", ip, port.Int())
return ctx, mqttC, mqttUri
}
func NewFakePublisher() *FakePublisher {
return &FakePublisher{msg: make(map[string]mqttdevice.MqttValue)}