Add unit test for result merging
@@ -5,6 +5,8 @@ import com.yahoo.config.provision.SystemName;
import com.yahoo.vespa.flags.FlagId;
import com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget;
import com.yahoo.vespa.hosted.controller.api.systemflags.v1.wire.WireSystemFlagsDeployResult;
+import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock;
+import com.yahoo.vespa.hosted.controller.integration.ZoneRegistryMock;
import org.junit.Test;
import java.util.List;
@@ -33,4 +35,37 @@ public class SystemFlagsDeployResultTest {
assertThat(wire.errors).hasSize(1);
assertThat(wire.errors.get(0).flagId).isEqualTo(flagTwo.toString());
}
+
+ @Test
+ public void identical_errors_and_changes_from_multiple_targets_are_merged() {
+ ZoneApiMock prodUsWest1Zone = ZoneApiMock.fromId("prod.us-west-1");
+ ZoneRegistryMock registry = new ZoneRegistryMock(SystemName.cd).setZones(prodUsWest1Zone);
+ FlagsTarget prodUsWest1Target = FlagsTarget.forConfigServer(registry, prodUsWest1Zone.getId());
+ FlagsTarget controllerTarget = FlagsTarget.forController(SystemName.cd);
+
+ FlagId flagOne = new FlagId("flagone");
+ FlagId flagTwo = new FlagId("flagtwo");
+
+ SystemFlagsDeployResult resultController =
+ new SystemFlagsDeployResult(
+ List.of(FlagDataChange.deleted(flagOne, controllerTarget)),
+ List.of(OperationError.deleteFailed("message", controllerTarget, flagTwo)));
+ SystemFlagsDeployResult resultProdUsWest1 =
+ new SystemFlagsDeployResult(
+ List.of(FlagDataChange.deleted(flagOne, prodUsWest1Target)),
+ List.of(OperationError.deleteFailed("message", prodUsWest1Target, flagTwo)));
+
+ var results = List.of(resultController, resultProdUsWest1);
+ SystemFlagsDeployResult mergedResult = merge(results);
+
+ List<FlagDataChange> changes = mergedResult.flagChanges();
+ assertThat(changes).hasSize(1);
+ FlagDataChange change = changes.get(0);
+ assertThat(change.targets()).containsOnly(controllerTarget, prodUsWest1Target);
+
+ List<OperationError> errors = mergedResult.errors();
+ assertThat(errors).hasSize(1);
+ OperationError error = errors.get(0);
+ assertThat(error.targets()).containsOnly(controllerTarget, prodUsWest1Target);
+ }
}
\ No newline at end of file
