Skip to content

Commit

Permalink
Add a big test of the new code
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Nov 19, 2024
1 parent 9b8f00d commit bb74cf6
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,45 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;

import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.sameInstance;

public class PipelineConfigurationTests extends AbstractXContentTestCase<PipelineConfiguration> {

public void testConfigInvariants() {
Map<String, Object> original = Map.of("a", 1);
Map<String, Object> mutable = new HashMap<>(original);
PipelineConfiguration configuration = new PipelineConfiguration("1", mutable);
// the config is equal to the original & mutable map, regardless of how you get a reference to it
assertThat(configuration.getConfig(), equalTo(original));
assertThat(configuration.getConfig(), equalTo(mutable));
assertThat(configuration.getConfig(), equalTo(configuration.getConfig(false)));
assertThat(configuration.getConfig(), equalTo(configuration.getConfig(true)));
// the config is the same instance as itself when unmodifiable is true
assertThat(configuration.getConfig(), sameInstance(configuration.getConfig()));
assertThat(configuration.getConfig(), sameInstance(configuration.getConfig(true)));
// but it's not the same instance as the original mutable map, nor if unmodifiable is false
assertThat(configuration.getConfig(), not(sameInstance(mutable)));
assertThat(configuration.getConfig(), not(sameInstance(configuration.getConfig(false))));

// changing the mutable map doesn't alter the pipeline's configuration
mutable.put("b", 2);
assertThat(configuration.getConfig(), equalTo(original));

// the modifiable map can be modified
Map<String, Object> modifiable = configuration.getConfig(false);
modifiable.put("c", 3); // this doesn't throw an exception
assertThat(modifiable.get("c"), equalTo(3));
// but the next modifiable copy is a new fresh copy, and doesn't reflect those changes
assertThat(configuration.getConfig(), equalTo(configuration.getConfig(false)));
}

public void testSerialization() throws IOException {
PipelineConfiguration configuration = new PipelineConfiguration(
"1",
Expand Down

0 comments on commit bb74cf6

Please sign in to comment.