mirror of
https://github.com/google/nomulus
synced 2026-09-22 07:54:22 +00:00
Add canary service to GKE (#2594)
This commit is contained in:
@@ -16,23 +16,65 @@ package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.request.Action.GaeService.DEFAULT;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.http.HttpHeaders;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpResponse;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.request.Action.GkeService;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link google.registry.tools.ServiceConnection}. */
|
||||
public class ServiceConnectionTest {
|
||||
|
||||
@Test
|
||||
void testServerUrl_notCanary() {
|
||||
void testSuccess_serverUrl_notCanary() {
|
||||
ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, false);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://default.example.com"); // See default-config.yaml
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServerUrl_canary() {
|
||||
void testFailure_mixedService() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
new ServiceConnection(true, null).withService(DEFAULT, true);
|
||||
});
|
||||
assertThat(thrown).hasMessageThat().contains("Cannot switch from GkeService to GaeService");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_serverUrl_gae_canary() {
|
||||
ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, true);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://nomulus-dot-default.example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_serverUrl_gke_canary() throws Exception {
|
||||
HttpRequestFactory factory = mock(HttpRequestFactory.class);
|
||||
HttpRequest request = mock(HttpRequest.class);
|
||||
HttpHeaders headers = mock(HttpHeaders.class);
|
||||
HttpResponse response = mock(HttpResponse.class);
|
||||
when(request.getHeaders()).thenReturn(headers);
|
||||
when(factory.buildGetRequest(any(GenericUrl.class))).thenReturn(request);
|
||||
when(request.execute()).thenReturn(response);
|
||||
when(response.getContent()).thenReturn(ByteArrayInputStream.nullInputStream());
|
||||
ServiceConnection connection =
|
||||
new ServiceConnection(true, factory).withService(GkeService.PUBAPI, true);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://pubapi.registry.test");
|
||||
connection.sendGetRequest("/path", ImmutableMap.of());
|
||||
verify(headers).set("canary", "true");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user