Reformat code
This commit is contained in:
parent
ae323d1690
commit
e5c81519bf
@ -18,7 +18,7 @@ func SetIntDefaultValueFromEnv(value *int, key string, defaultValue int) error {
|
|||||||
if os.Getenv(key) != "" {
|
if os.Getenv(key) != "" {
|
||||||
sVal = os.Getenv(key)
|
sVal = os.Getenv(key)
|
||||||
val, err := strconv.Atoi(sVal)
|
val, err := strconv.Atoi(sVal)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
log.Printf("unable to convert string to int: %v", err)
|
log.Printf("unable to convert string to int: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ func TestSetDefaultValueFromEnv(t *testing.T) {
|
|||||||
t.Errorf("unable to set env value: %v", err)
|
t.Errorf("unable to set env value: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cases := []struct{
|
cases := []struct {
|
||||||
key string
|
key string
|
||||||
defValue string
|
defValue string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
@ -36,10 +36,10 @@ func TestSetIntDefaultValueFromEnv(t *testing.T) {
|
|||||||
t.Errorf("unable to set env value: %v", err)
|
t.Errorf("unable to set env value: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cases := []struct{
|
cases := []struct {
|
||||||
key string
|
key string
|
||||||
defValue int
|
defValue int
|
||||||
expected int
|
expected int
|
||||||
withError bool
|
withError bool
|
||||||
}{
|
}{
|
||||||
{"MISSING_KEY", 3, 3, false},
|
{"MISSING_KEY", 3, 3, false},
|
||||||
@ -51,11 +51,11 @@ func TestSetIntDefaultValueFromEnv(t *testing.T) {
|
|||||||
var value = 0
|
var value = 0
|
||||||
err := SetIntDefaultValueFromEnv(&value, c.key, c.defValue)
|
err := SetIntDefaultValueFromEnv(&value, c.key, c.defValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !c.withError{
|
if !c.withError {
|
||||||
t.Errorf("SetIntDefaultValueFromEnv(*value, %v, %v): %v", c.key, c.defValue, err)
|
t.Errorf("SetIntDefaultValueFromEnv(*value, %v, %v): %v", c.key, c.defValue, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.withError && err == nil{
|
if c.withError && err == nil {
|
||||||
t.Errorf("SetIntDefaultValueFromEnv(*value, %v, %v): %v, wants an error", c.key, c.defValue, value)
|
t.Errorf("SetIntDefaultValueFromEnv(*value, %v, %v): %v, wants an error", c.key, c.defValue, value)
|
||||||
} else if c.expected != value {
|
} else if c.expected != value {
|
||||||
t.Errorf("SetDefaultValueFromEnv(*value, %v, %v): %v, wants %v", c.key, c.defValue, value, c.expected)
|
t.Errorf("SetDefaultValueFromEnv(*value, %v, %v): %v, wants %v", c.key, c.defValue, value, c.expected)
|
||||||
|
@ -3,8 +3,8 @@ package mode
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestToString(t *testing.T) {
|
func TestToString(t *testing.T) {
|
||||||
cases := []struct{
|
cases := []struct {
|
||||||
value DriveMode
|
value DriveMode
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{DriveModeUser, "user"},
|
{DriveModeUser, "user"},
|
||||||
@ -12,28 +12,28 @@ func TestToString(t *testing.T) {
|
|||||||
{DriveModeInvalid, ""},
|
{DriveModeInvalid, ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val := ToString(c.value)
|
val := ToString(c.value)
|
||||||
if val != c.expected{
|
if val != c.expected {
|
||||||
t.Errorf("ToString(%v): %v, wants %v", c.value, val, c.expected)
|
t.Errorf("ToString(%v): %v, wants %v", c.value, val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseString(t *testing.T) {
|
func TestParseString(t *testing.T) {
|
||||||
cases := []struct{
|
cases := []struct {
|
||||||
value string
|
value string
|
||||||
expected DriveMode
|
expected DriveMode
|
||||||
}{
|
}{
|
||||||
{"user", DriveModeUser},
|
{"user", DriveModeUser},
|
||||||
{"pilot",DriveModePilot},
|
{"pilot", DriveModePilot},
|
||||||
{"", DriveModeInvalid},
|
{"", DriveModeInvalid},
|
||||||
{"invalid", DriveModeInvalid},
|
{"invalid", DriveModeInvalid},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val := ParseString(c.value)
|
val := ParseString(c.value)
|
||||||
if val != c.expected{
|
if val != c.expected {
|
||||||
t.Errorf("ParseString(%v): %v, wants %v", c.value, val, c.expected)
|
t.Errorf("ParseString(%v): %v, wants %v", c.value, val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,12 +103,12 @@ func TestMqttValue_ByteSliceValue(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{NewMqttValue([]byte("content")), []byte("content")},
|
{NewMqttValue([]byte("content")), []byte("content")},
|
||||||
}
|
}
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val, err := c.value.ByteSliceValue()
|
val, err := c.value.ByteSliceValue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected conversion error: %v", err)
|
t.Errorf("unexpected conversion error: %v", err)
|
||||||
}
|
}
|
||||||
if string(c.expected) != string(val){
|
if string(c.expected) != string(val) {
|
||||||
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,12 +122,12 @@ func TestMqttValue_Float32Value(t *testing.T) {
|
|||||||
{NewMqttValue("32.0123"), float32(32.0123)},
|
{NewMqttValue("32.0123"), float32(32.0123)},
|
||||||
{NewMqttValue("33"), float32(33.)},
|
{NewMqttValue("33"), float32(33.)},
|
||||||
}
|
}
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val, err := c.value.Float32Value()
|
val, err := c.value.Float32Value()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected conversion error: %v", err)
|
t.Errorf("unexpected conversion error: %v", err)
|
||||||
}
|
}
|
||||||
if c.expected != val{
|
if c.expected != val {
|
||||||
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,12 +141,12 @@ func TestMqttValue_Float64Value(t *testing.T) {
|
|||||||
{NewMqttValue("32.0123"), 32.0123},
|
{NewMqttValue("32.0123"), 32.0123},
|
||||||
{NewMqttValue("33"), 33.},
|
{NewMqttValue("33"), 33.},
|
||||||
}
|
}
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val, err := c.value.Float64Value()
|
val, err := c.value.Float64Value()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected conversion error: %v", err)
|
t.Errorf("unexpected conversion error: %v", err)
|
||||||
}
|
}
|
||||||
if c.expected != val{
|
if c.expected != val {
|
||||||
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,12 +159,12 @@ func TestMqttValue_IntValue(t *testing.T) {
|
|||||||
{NewMqttValue("1"), 1},
|
{NewMqttValue("1"), 1},
|
||||||
{NewMqttValue("-10"), -10},
|
{NewMqttValue("-10"), -10},
|
||||||
}
|
}
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val, err := c.value.IntValue()
|
val, err := c.value.IntValue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected conversion error: %v", err)
|
t.Errorf("unexpected conversion error: %v", err)
|
||||||
}
|
}
|
||||||
if c.expected != val{
|
if c.expected != val {
|
||||||
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,12 +177,12 @@ func TestMqttValue_StringValue(t *testing.T) {
|
|||||||
{NewMqttValue("ON"), "ON"},
|
{NewMqttValue("ON"), "ON"},
|
||||||
{NewMqttValue("OFF"), "OFF"},
|
{NewMqttValue("OFF"), "OFF"},
|
||||||
}
|
}
|
||||||
for _, c := range cases{
|
for _, c := range cases {
|
||||||
val, err := c.value.StringValue()
|
val, err := c.value.StringValue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected conversion error: %v", err)
|
t.Errorf("unexpected conversion error: %v", err)
|
||||||
}
|
}
|
||||||
if c.expected != val{
|
if c.expected != val {
|
||||||
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
t.Errorf("MqttValue.BoolValue(): %v, wants %v", val, c.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ func MqttContainer(t *testing.T) (context.Context, testcontainers.Container, str
|
|||||||
return ctx, mqttC, mqttUri
|
return ctx, mqttC, mqttUri
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakePublisher() *FakePublisher{
|
func NewFakePublisher() *FakePublisher {
|
||||||
return &FakePublisher{msg:make(map[string]mqttdevice.MqttValue)}
|
return &FakePublisher{msg: make(map[string]mqttdevice.MqttValue)}
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakePublisher struct {
|
type FakePublisher struct {
|
||||||
@ -103,4 +103,3 @@ func NewFakeMessage(topic string, payload []byte) mqtt.Message {
|
|||||||
acked: false,
|
acked: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user