func TestShouldReturnAWrapperThatDefaultsToAGivenValueIfTheKeyDoesNotExist(t *testing.T) { setupConsul(t) expectedValue := "defValue" f := configurator.DefaultsTo(configurator.GetString, expectedValue) actualValue := f("nonExistantKey") if actualValue != expectedValue { t.Errorf("%s should be %s", actualValue, expectedValue) } }
func TestDefaultsToWrapperShouldReturnActualValueIfTheKeyExists(t *testing.T) { setupConsul(t) f := configurator.DefaultsTo(configurator.GetString, "A default value") actualValue := f(expectedKeyWithStringValue) expectedValue := expectedConfiguration[expectedKeyWithStringValue] if actualValue != expectedValue { t.Errorf("%s should be %s", actualValue, expectedValue) } }
func TestShouldReturnAWrapperThatConvertsToAnInteger(t *testing.T) { setupConsul(t) g := configurator.DefaultsTo(configurator.GetString, "5") f := configurator.AsInt(g) expectedValue, _ := strconv.Atoi(expectedConfiguration[expectedKeyWithIntValue]) actualValue := f(expectedKeyWithIntValue) if actualValue != expectedValue { t.Errorf("%s should be %s", actualValue, expectedValue) } }