[mqtt] Implements mqtt publish tooling

This commit is contained in:
2019-11-30 21:49:19 +01:00
parent 1b62903474
commit 17beea7e8a
921 changed files with 306092 additions and 0 deletions

37
mode/mode.go Normal file
View File

@ -0,0 +1,37 @@
package mode
import (
"log"
)
type DriveMode int
const (
DriveModeInvalid = -1
DriveModeUser = iota
DriveModePilot
)
func ToString(mode DriveMode) string {
switch mode {
case DriveModeUser:
return "user"
case DriveModePilot:
return "pilot"
default:
return ""
}
}
func ParseString(val string) DriveMode {
switch val {
case "user":
return DriveModeUser
case "pilot":
return DriveModePilot
default:
log.Printf("invalid DriveMode: %v", val)
return DriveModeInvalid
}
}

40
mode/mode_test.go Normal file
View File

@ -0,0 +1,40 @@
package mode
import "testing"
func TestToString(t *testing.T) {
cases := []struct{
value DriveMode
expected string
}{
{DriveModeUser, "user"},
{DriveModePilot, "pilot"},
{DriveModeInvalid, ""},
}
for _, c := range cases{
val := ToString(c.value)
if val != c.expected{
t.Errorf("ToString(%v): %v, wants %v", c.value, val, c.expected)
}
}
}
func TestParseString(t *testing.T) {
cases := []struct{
value string
expected DriveMode
}{
{"user", DriveModeUser},
{"pilot",DriveModePilot},
{"", DriveModeInvalid},
{"invalid", DriveModeInvalid},
}
for _, c := range cases{
val := ParseString(c.value)
if val != c.expected{
t.Errorf("ParseString(%v): %v, wants %v", c.value, val, c.expected)
}
}
}