Reformat code

This commit is contained in:
Cyrille Nofficial 2019-12-14 10:43:02 +01:00
parent ae323d1690
commit e5c81519bf
5 changed files with 30 additions and 31 deletions

View File

@ -18,7 +18,7 @@ func SetIntDefaultValueFromEnv(value *int, key string, defaultValue int) error {
if os.Getenv(key) != "" {
sVal = os.Getenv(key)
val, err := strconv.Atoi(sVal)
if err != nil{
if err != nil {
log.Printf("unable to convert string to int: %v", err)
return err
}

View File

@ -11,8 +11,8 @@ func TestSetDefaultValueFromEnv(t *testing.T) {
t.Errorf("unable to set env value: %v", err)
}
cases := []struct{
key string
cases := []struct {
key string
defValue string
expected string
}{
@ -36,10 +36,10 @@ func TestSetIntDefaultValueFromEnv(t *testing.T) {
t.Errorf("unable to set env value: %v", err)
}
cases := []struct{
key string
defValue int
expected int
cases := []struct {
key string
defValue int
expected int
withError bool
}{
{"MISSING_KEY", 3, 3, false},
@ -51,11 +51,11 @@ func TestSetIntDefaultValueFromEnv(t *testing.T) {
var value = 0
err := SetIntDefaultValueFromEnv(&value, c.key, c.defValue)
if err != nil {
if !c.withError{
if !c.withError {
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)
} else if c.expected != value {
t.Errorf("SetDefaultValueFromEnv(*value, %v, %v): %v, wants %v", c.key, c.defValue, value, c.expected)

View File

@ -3,8 +3,8 @@ package mode
import "testing"
func TestToString(t *testing.T) {
cases := []struct{
value DriveMode
cases := []struct {
value DriveMode
expected string
}{
{DriveModeUser, "user"},
@ -12,28 +12,28 @@ func TestToString(t *testing.T) {
{DriveModeInvalid, ""},
}
for _, c := range cases{
for _, c := range cases {
val := ToString(c.value)
if val != c.expected{
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
cases := []struct {
value string
expected DriveMode
}{
{"user", DriveModeUser},
{"pilot",DriveModePilot},
{"pilot", DriveModePilot},
{"", DriveModeInvalid},
{"invalid", DriveModeInvalid},
}
for _, c := range cases{
for _, c := range cases {
val := ParseString(c.value)
if val != c.expected{
if val != c.expected {
t.Errorf("ParseString(%v): %v, wants %v", c.value, val, c.expected)
}
}

View File

@ -103,12 +103,12 @@ func TestMqttValue_ByteSliceValue(t *testing.T) {
}{
{NewMqttValue([]byte("content")), []byte("content")},
}
for _, c := range cases{
for _, c := range cases {
val, err := c.value.ByteSliceValue()
if err != nil {
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)
}
}
@ -122,12 +122,12 @@ func TestMqttValue_Float32Value(t *testing.T) {
{NewMqttValue("32.0123"), float32(32.0123)},
{NewMqttValue("33"), float32(33.)},
}
for _, c := range cases{
for _, c := range cases {
val, err := c.value.Float32Value()
if err != nil {
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)
}
}
@ -141,12 +141,12 @@ func TestMqttValue_Float64Value(t *testing.T) {
{NewMqttValue("32.0123"), 32.0123},
{NewMqttValue("33"), 33.},
}
for _, c := range cases{
for _, c := range cases {
val, err := c.value.Float64Value()
if err != nil {
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)
}
}
@ -159,12 +159,12 @@ func TestMqttValue_IntValue(t *testing.T) {
{NewMqttValue("1"), 1},
{NewMqttValue("-10"), -10},
}
for _, c := range cases{
for _, c := range cases {
val, err := c.value.IntValue()
if err != nil {
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)
}
}
@ -177,12 +177,12 @@ func TestMqttValue_StringValue(t *testing.T) {
{NewMqttValue("ON"), "ON"},
{NewMqttValue("OFF"), "OFF"},
}
for _, c := range cases{
for _, c := range cases {
val, err := c.value.StringValue()
if err != nil {
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)
}
}

View File

@ -39,8 +39,8 @@ func MqttContainer(t *testing.T) (context.Context, testcontainers.Container, str
return ctx, mqttC, mqttUri
}
func NewFakePublisher() *FakePublisher{
return &FakePublisher{msg:make(map[string]mqttdevice.MqttValue)}
func NewFakePublisher() *FakePublisher {
return &FakePublisher{msg: make(map[string]mqttdevice.MqttValue)}
}
type FakePublisher struct {
@ -103,4 +103,3 @@ func NewFakeMessage(topic string, payload []byte) mqtt.Message {
acked: false,
}
}