use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.
the class FeatureToggleRepositoryTest method shouldReadFeatureTogglesFromAvailableTogglesFile.
@Test
public void shouldReadFeatureTogglesFromAvailableTogglesFile() throws Exception {
FeatureToggle featureToggle1 = new FeatureToggle("key1", "desc1", true);
FeatureToggle featureToggle2 = new FeatureToggle("key2", "desc2", false);
setupAvailableToggles(featureToggle1, featureToggle2);
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
assertThat(repository.availableToggles(), is(new FeatureToggles(featureToggle1, featureToggle2)));
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.
the class FeatureToggleRepositoryTest method shouldFailWhenUnableToWriteToUserTogglesFile_DuringChangingOfAToggleValue.
@Test
public void shouldFailWhenUnableToWriteToUserTogglesFile_DuringChangingOfAToggleValue() throws Exception {
setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
File userTogglesFile = setupUserToggles(new FeatureToggle("key1", "desc1", true));
userTogglesFile.setReadOnly();
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
try {
repository.changeValueOfToggle("key1", false);
fail("Should have failed to write");
} catch (RuntimeException e) {
assertThat(e.getMessage(), containsString(userTogglesFile.getPath()));
}
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.
the class FeatureToggleRepositoryTest method shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesNotExist.
@Test
public void shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesNotExist() throws Exception {
File togglesDir = TestFileUtil.createTempFolder("toggles.dir");
File nonExistentUserToggleFile = new File(togglesDir, "a-non-existent-file");
setupUserToggleFileAs(nonExistentUserToggleFile);
setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
repository.changeValueOfToggle("key1", false);
assertThat(repository.availableToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true))));
assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", null, false))));
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.
the class FeatureToggleRepositoryTest method whileChangingAToggleValue_shouldNotPersist_ValueHasBeenChangedFlag.
@Test
public void whileChangingAToggleValue_shouldNotPersist_ValueHasBeenChangedFlag() throws Exception {
String fieldForHasBeenChangedFlag = "hasBeenChangedFromDefault";
assertNotNull("This can never be null, but can throw an exception. If you've renamed the field mentioned above" + "(in FeatureToggle class), please change it in this test too. Otherwise, this test can pass, wrongly.", FeatureToggle.class.getDeclaredField(fieldForHasBeenChangedFlag));
setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
File userTogglesFile = setupUserToggles(new FeatureToggle("key1", "desc1", false).withValueHasBeenChangedFlag(true));
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
repository.changeValueOfToggle("key1", false);
assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", false).withValueHasBeenChangedFlag(false))));
assertThat(FileUtils.readFileToString(userTogglesFile), containsString("key1"));
assertThat(FileUtils.readFileToString(userTogglesFile), containsString("desc1"));
assertThat(FileUtils.readFileToString(userTogglesFile), not(containsString(fieldForHasBeenChangedFlag)));
/* The first time the file is written, it is written by hand in this test. Force it to write again,
* so that the actual JSON write logic is used.
*/
repository.changeValueOfToggle("key1", true);
assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true).withValueHasBeenChangedFlag(false))));
assertThat(FileUtils.readFileToString(userTogglesFile), containsString("key1"));
assertThat(FileUtils.readFileToString(userTogglesFile), containsString("desc1"));
assertThat(FileUtils.readFileToString(userTogglesFile), not(containsString(fieldForHasBeenChangedFlag)));
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.
the class FeatureToggleRepositoryTest method shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesExist.
@Test
public void shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesExist() throws Exception {
setupAvailableToggles(new FeatureToggle("key1", "desc1", true), new FeatureToggle("key2", "desc2", true));
setupUserToggles(new FeatureToggle("key1", "desc1", true));
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
repository.changeValueOfToggle("key1", false);
assertThat(repository.availableToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true), new FeatureToggle("key2", "desc2", true))));
assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", false))));
}
Aggregations