Error handling if public ips are missing
This commit is contained in:
parent
523936efb4
commit
5a0e87be54
2 changed files with 23 additions and 11 deletions
|
@ -53,6 +53,10 @@ public class Updater {
|
|||
|
||||
Addresses publicIps = publicIpLookup.get();
|
||||
log.debugf("Public ips - v4: %s, v6: %s", publicIps.v4(), publicIps.v6());
|
||||
if (publicIps.v4().isEmpty() && publicIps.v6().isEmpty()) {
|
||||
log.error("No public ips present, stopping");
|
||||
return;
|
||||
}
|
||||
|
||||
config.forEach(cfg -> {
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
@ -40,6 +41,7 @@ class UpdaterTest {
|
|||
@Test
|
||||
void should_throw_exception_if_config_is_empty() {
|
||||
Config config = new Config();
|
||||
PublicIpLookup publicIpLookup = mock(PublicIpLookup.class);
|
||||
Updater updater = new Updater(dyndnsProviderRegistry, publicIpLookup, dnsResolver, config, backoff);
|
||||
Assertions.assertThrows(IllegalStateException.class, updater::run);
|
||||
}
|
||||
|
@ -47,7 +49,6 @@ class UpdaterTest {
|
|||
@Test
|
||||
void should_process_all_config_entries() {
|
||||
Addresses ips = new Addresses("ipv4", "ipv6");
|
||||
|
||||
when(publicIpLookup.get()).thenReturn(ips);
|
||||
when(dnsResolver.resolve(any())).thenReturn(ips);
|
||||
|
||||
|
@ -89,17 +90,27 @@ class UpdaterTest {
|
|||
when(dyndnsProviderRegistry.get("ddnss")).thenReturn(ddnss);
|
||||
|
||||
Addresses publicIps = new Addresses("ipv4", "ipv6");
|
||||
|
||||
when(publicIpLookup.get()).thenReturn(publicIps);
|
||||
when(dnsResolver.resolve("example.org")).thenReturn(new Addresses("registered_ipv4", "registered_ipv6"));
|
||||
|
||||
Updater updater = new Updater(dyndnsProviderRegistry, publicIpLookup, dnsResolver, ddnssConfig, backoff);
|
||||
updater.run();
|
||||
|
||||
verify(ddnss).update(
|
||||
"example.org",
|
||||
publicIps,
|
||||
new DyndnsAuth(null, null, "token")
|
||||
);
|
||||
verify(ddnss).update("example.org", publicIps, new DyndnsAuth(null, null, "token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_not_trigger_dyndns_update_if_public_ips_are_empty() {
|
||||
|
||||
Addresses publicIps = new Addresses(Optional.empty(), Optional.empty());
|
||||
|
||||
when(publicIpLookup.get()).thenReturn(publicIps);
|
||||
|
||||
Updater updater = new Updater(dyndnsProviderRegistry, publicIpLookup, dnsResolver, ddnssConfig, backoff);
|
||||
updater.run();
|
||||
|
||||
verify(dyndnsProviderRegistry, never()).get(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -110,6 +121,7 @@ class UpdaterTest {
|
|||
when(dyndnsProviderRegistry.get("ddnss")).thenReturn(ddnss);
|
||||
|
||||
Addresses publicIps = new Addresses("ipv4", "ipv6");
|
||||
|
||||
when(publicIpLookup.get()).thenReturn(publicIps);
|
||||
when(dnsResolver.resolve("example.org")).thenReturn(new Addresses("registered_ipv4", "registered_ipv6"));
|
||||
|
||||
|
@ -118,11 +130,7 @@ class UpdaterTest {
|
|||
|
||||
updater.run();
|
||||
|
||||
verify(ddnss, times(1)).update(
|
||||
"example.org",
|
||||
publicIps,
|
||||
new DyndnsAuth(null, null, "token")
|
||||
);
|
||||
verify(ddnss, times(1)).update("example.org", publicIps, new DyndnsAuth(null, null, "token"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue