mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 20:47:52 +02:00
Automated g4 rollback of changelist 171011304. Please see history below, the original CL was [] Rolling back and re-mailing so I can get a readability review on it. *** Reason for rollback *** Re-opening for readability review. *** Original change description *** Automated g4 rollback of changelist 170906329. *** Reason for rollback *** Forgot to send this for readability review. *** Original change description *** Add "create_cdns_tld" command to nomulus Add a command to allow us to create the managed zone for a new TLD in cloud dns. Note: this implementation is problematic, it's currently doing its own thing as far as credentials and http transport, making it unusable with the [] channel and the credentials generated by login. Unfortunately, fixing the plumbing to make it work right is difficult, and we have an immediate need for this functionality. *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171161371
77 lines
2.8 KiB
Java
77 lines
2.8 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.tools;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import com.google.api.services.dns.Dns;
|
|
import com.google.api.services.dns.model.ManagedZone;
|
|
import java.io.IOException;
|
|
import java.security.GeneralSecurityException;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.ArgumentCaptor;
|
|
import org.mockito.Captor;
|
|
import org.mockito.Mock;
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
|
|
|
|
@Mock Dns dnsService;
|
|
@Mock Dns.ManagedZones managedZones;
|
|
@Mock Dns.ManagedZones.Create request;
|
|
@Captor ArgumentCaptor<String> projectId;
|
|
@Captor ArgumentCaptor<ManagedZone> requestBody;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
when(dnsService.managedZones()).thenReturn(managedZones);
|
|
when(managedZones.create(projectId.capture(), requestBody.capture())).thenReturn(request);
|
|
command = new CreateCdnsTldForTest();
|
|
command.projectId = "test-project";
|
|
}
|
|
|
|
/** Fake the command class so we can override createDnsService() */
|
|
class CreateCdnsTldForTest extends CreateCdnsTld {
|
|
@Override
|
|
Dns createDnsService() throws IOException, GeneralSecurityException {
|
|
return dnsService;
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testBasicFunctionality() throws Exception {
|
|
runCommand("--dns_name=tld.", "--name=tld", "--description=test run");
|
|
verify(request).execute();
|
|
assertThat(projectId.getValue()).isEqualTo("test-project");
|
|
ManagedZone zone = requestBody.getValue();
|
|
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
|
|
assertThat(zone.getDnsName()).isEqualTo("tld.");
|
|
assertThat(zone.getName()).isEqualTo("tld");
|
|
}
|
|
|
|
@Test
|
|
public void testNameDefault() throws Exception {
|
|
runCommand("--dns_name=tld.", "--description=test run");
|
|
ManagedZone zone = requestBody.getValue();
|
|
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
|
|
assertThat(zone.getDnsName()).isEqualTo("tld.");
|
|
assertThat(zone.getName()).isEqualTo("tld.");
|
|
}
|
|
}
|