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 (
|
|
|
|
expected = "expected"
|
|
|
|
)
|
|
|
|
|
2019-03-13 04:14:30 -07:00
|
|
|
func TestGetString(t *testing.T) {
|
|
|
|
values := map[Property]interface{}{TextProperty: expected}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
values := map[Property]interface{}{}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
values := map[Property]interface{}{TextProperty: true}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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
|
2019-03-13 04:14:30 -07:00
|
|
|
values := map[Property]interface{}{UserColor: expected}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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"
|
|
|
|
values := map[Property]interface{}{UserColor: expected}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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
|
2019-03-13 04:14:30 -07:00
|
|
|
values := map[Property]interface{}{UserColor: "invalid"}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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
|
2019-03-13 04:14:30 -07:00
|
|
|
values := map[Property]interface{}{}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
|
|
|
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 TestGetBool(t *testing.T) {
|
|
|
|
expected := true
|
2020-10-03 11:11:44 -07:00
|
|
|
values := map[Property]interface{}{DisplayHost: expected}
|
2019-03-13 04:14:30 -07:00
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
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) {
|
|
|
|
values := map[Property]interface{}{}
|
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
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) {
|
2020-10-03 11:11:44 -07:00
|
|
|
values := map[Property]interface{}{DisplayHost: "borked"}
|
2019-03-13 04:14:30 -07:00
|
|
|
properties := properties{
|
|
|
|
values: values,
|
|
|
|
}
|
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)
|
|
|
|
}
|