Esempio n. 1
0
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)
	}
}
Esempio n. 2
0
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)
	}
}
Esempio n. 3
0
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)
	}

}