2019-03-13 04:14:30 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-11-12 00:43:32 -08:00
|
|
|
const (
|
2021-04-15 10:51:54 -07:00
|
|
|
expected = "expected"
|
|
|
|
expectedColor = "#768954"
|
2020-11-12 00:43:32 -08:00
|
|
|
)
|
|
|
|
|
2019-03-13 04:14:30 -07:00
|
|
|
func TestGetString(t *testing.T) {
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{TextProperty: expected}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getString(TextProperty, "err")
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetStringNoEntry(t *testing.T) {
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getString(TextProperty, expected)
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetStringNoTextEntry(t *testing.T) {
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{TextProperty: true}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getString(TextProperty, expected)
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
2020-11-15 05:32:07 -08:00
|
|
|
func TestGetHexColor(t *testing.T) {
|
2020-11-12 00:43:32 -08:00
|
|
|
expected := expectedColor
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{UserColor: expected}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getColor(UserColor, "#789123")
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetColor(t *testing.T) {
|
|
|
|
expected := "yellow"
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{UserColor: expected}
|
2020-11-15 05:32:07 -08:00
|
|
|
value := properties.getColor(UserColor, "#789123")
|
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
2020-11-12 00:43:32 -08:00
|
|
|
expected := expectedColor
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{UserColor: "invalid"}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getColor(UserColor, expected)
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
2020-11-12 00:43:32 -08:00
|
|
|
expected := expectedColor
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{}
|
2019-03-13 04:14:30 -07:00
|
|
|
value := properties.getColor(UserColor, expected)
|
2020-11-15 05:32:07 -08:00
|
|
|
assert.Equal(t, expected, value)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
2021-11-22 06:25:56 -08:00
|
|
|
func TestGetPaletteColor(t *testing.T) {
|
|
|
|
expected := "p:red"
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{Background: expected}
|
2021-11-22 06:25:56 -08:00
|
|
|
value := properties.getColor(Background, "white")
|
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|
|
|
|
|
2019-03-13 04:14:30 -07:00
|
|
|
func TestGetBool(t *testing.T) {
|
|
|
|
expected := true
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{DisplayHost: expected}
|
2020-10-03 11:11:44 -07:00
|
|
|
value := properties.getBool(DisplayHost, false)
|
2019-03-13 04:14:30 -07:00
|
|
|
assert.True(t, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBoolPropertyNotInMap(t *testing.T) {
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{}
|
2020-10-03 11:11:44 -07:00
|
|
|
value := properties.getBool(DisplayHost, false)
|
2019-03-13 04:14:30 -07:00
|
|
|
assert.False(t, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBoolInvalidProperty(t *testing.T) {
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{DisplayHost: "borked"}
|
2020-10-03 11:11:44 -07:00
|
|
|
value := properties.getBool(DisplayHost, false)
|
2019-03-13 04:14:30 -07:00
|
|
|
assert.False(t, value)
|
|
|
|
}
|
2020-12-06 13:03:40 -08:00
|
|
|
|
|
|
|
func TestGetFloat64(t *testing.T) {
|
|
|
|
expected := float64(1337)
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{"myfloat": expected}
|
2020-12-06 13:03:40 -08:00
|
|
|
value := properties.getFloat64("myfloat", 9001)
|
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFloat64PropertyNotInMap(t *testing.T) {
|
|
|
|
expected := float64(1337)
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{}
|
2020-12-06 13:03:40 -08:00
|
|
|
value := properties.getFloat64(ThresholdProperty, expected)
|
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFloat64InvalidStringProperty(t *testing.T) {
|
|
|
|
expected := float64(1337)
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{ThresholdProperty: "invalid"}
|
2020-12-06 13:03:40 -08:00
|
|
|
value := properties.getFloat64(ThresholdProperty, expected)
|
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFloat64InvalidBoolProperty(t *testing.T) {
|
|
|
|
expected := float64(1337)
|
2022-01-01 11:08:08 -08:00
|
|
|
var properties properties = properties{ThresholdProperty: true}
|
2020-12-06 13:03:40 -08:00
|
|
|
value := properties.getFloat64(ThresholdProperty, expected)
|
|
|
|
assert.Equal(t, expected, value)
|
|
|
|
}
|