use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method getServiceTest.
@Test
public void getServiceTest() throws Exception {
Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
mockServiceMonitoringService.addResponse(expectedResponse);
ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
Service actualResponse = client.getService(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetServiceRequest actualRequest = ((GetServiceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceExceptionTest4.
@Test
public void createServiceExceptionTest4() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
String parent = "parent-995424086";
Service service = Service.newBuilder().build();
client.createService(parent, service);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method listServicesTest.
@Test
public void listServicesTest() throws Exception {
Service responsesElement = Service.newBuilder().build();
ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
mockServiceMonitoringService.addResponse(expectedResponse);
FolderName parent = FolderName.of("[FOLDER]");
ListServicesPagedResponse pagedListResponse = client.listServices(parent);
List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceExceptionTest.
@Test
public void createServiceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
FolderName parent = FolderName.of("[FOLDER]");
Service service = Service.newBuilder().build();
client.createService(parent, service);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project yakc by manusa.
the class AuthIT method retrieveSecretForServiceAccount.
private Secret retrieveSecretForServiceAccount() throws IOException {
final ServiceAccount sa = KC.create(CoreV1Api.class).listNamespacedServiceAccount(NAMESPACE).stream().findFirst().orElseThrow(() -> new AssertionError("No Service Account found"));
final String secretName = sa.getSecrets() == null ? null : sa.getSecrets().stream().findFirst().map(ObjectReference::getName).orElse(null);
if (secretName != null) {
return KC.create(CoreV1Api.class).listNamespacedSecret(NAMESPACE).stream().filter(s -> s.getType().equals("kubernetes.io/service-account-token")).filter(s -> s.getMetadata().getName().equals(secretName)).findAny().orElseThrow(() -> new AssertionError(String.format("Secret %s doesn't exist", secretName)));
} else {
// https://kubernetes.io/docs/concepts/configuration/secret/#service-account-token-secrets
final Secret serviceAccountTokenSecret = Secret.builder().metadata(ObjectMeta.builder().name(sa.getMetadata().getName() + "-token").putInAnnotations("kubernetes.io/service-account.name", sa.getMetadata().getName()).build()).type("kubernetes.io/service-account-token").putInStringData("token", "my-secret-token").build();
return KC.create(CoreV1Api.class).createNamespacedSecret(NAMESPACE, serviceAccountTokenSecret).get();
}
}
Aggregations