Skip to content

Commit

Permalink
Merge branch 'master' into users/svegira/make-context-mockable
Browse files Browse the repository at this point in the history
  • Loading branch information
siri-varma authored Oct 11, 2024
2 parents f51def0 + 4d78706 commit b772daf
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2390,10 +2390,14 @@ public override async Task<DaprMetadata> GetMetadataAsync(CancellationToken canc
try
{
var response = await client.GetMetadataAsync(new Autogenerated.GetMetadataRequest(), options);
return new DaprMetadata(response.Id,
response.ActorRuntime.ActiveActors.Select(c => new DaprActorMetadata(c.Type, c.Count)).ToList(),
response.ExtendedMetadata.ToDictionary(c => c.Key, c => c.Value),
response.RegisteredComponents.Select(c => new DaprComponentsMetadata(c.Name, c.Type, c.Version, c.Capabilities.ToArray())).ToList());
return new DaprMetadata(response.Id ?? "",
response.ActorRuntime?.ActiveActors?.Select(c => new DaprActorMetadata(c.Type, c.Count)).ToList() ??
new List<DaprActorMetadata>(),
response.ExtendedMetadata?.ToDictionary(c => c.Key, c => c.Value) ??
new Dictionary<string, string>(),
response.RegisteredComponents?.Select(c =>
new DaprComponentsMetadata(c.Name, c.Type, c.Version, c.Capabilities.ToArray())).ToList() ??
new List<DaprComponentsMetadata>());
}
catch (RpcException ex)
{
Expand Down
1 change: 0 additions & 1 deletion src/Dapr.Client/DaprMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System;
using System.Collections.Generic;

namespace Dapr.Client
Expand Down
29 changes: 29 additions & 0 deletions test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Linq;
using System.Net.Http.Headers;

namespace Dapr.Client.Test
{
using System;
Expand Down Expand Up @@ -654,8 +657,34 @@ public async Task CreateInvokeMethodRequest_WithData_CreatesJsonContentWithQuery
var actual = await content.ReadFromJsonAsync<Widget>(this.jsonSerializerOptions);
Assert.Equal(data.Color, actual.Color);
}

[Fact]
public async Task InvokeMethodWithoutResponse_WithExtraneousHeaders()
{
await using var client = TestClient.CreateForDaprClient(c =>
{
c.UseGrpcEndpoint("http://localhost").UseHttpEndpoint("https://test-endpoint:3501").UseJsonSerializationOptions(this.jsonSerializerOptions);
});

var req = await client.CaptureHttpRequestAsync(async DaprClient =>
{
var request = client.InnerClient.CreateInvokeMethodRequest(HttpMethod.Get, "test-app", "mymethod");
request.Headers.Add("test-api-key", "test");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "abc123");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
await DaprClient.InvokeMethodAsync(request);
});

req.Dismiss();

Assert.NotNull(req);
Assert.True(req.Request.Headers.Contains("test-api-key"));
Assert.Equal("test", req.Request.Headers.GetValues("test-api-key").First());
Assert.True(req.Request.Headers.Contains("Authorization"));
Assert.Equal("Bearer abc123", req.Request.Headers.GetValues("Authorization").First());
Assert.Equal("application/json", req.Request.Headers.GetValues("Accept").First());
}

[Fact]
public async Task InvokeMethodWithResponseAsync_ReturnsMessageWithoutCheckingStatus()
Expand Down
28 changes: 27 additions & 1 deletion test/Dapr.Client.Test/SecretApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,6 +93,32 @@ public async Task GetSecretAsync_ReturnSingleSecret()
secretsResponse["redis_secret"].Should().Be("Guess_Redis");
}

[Fact]
public async Task GetSecretAsync_WithSlashesInName()
{
await using var client = TestClient.CreateForDaprClient();

var request = await client.CaptureGrpcRequestAsync(async DaprClient =>
{
return await DaprClient.GetSecretAsync("testStore", "us-west-1/org/xpto/secretabc");
});

request.Dismiss();

//Get Request and validate
var envelope = await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();
envelope.StoreName.Should().Be("testStore");
envelope.Key.Should().Be("us-west-1/org/xpto/secretabc");

var secrets = new Dictionary<string, string> { { "us-west-1/org/xpto/secretabc", "abc123" } };
var secretsResponse = await SendResponseWithSecrets(secrets, request);

//Get response and validate
secretsResponse.Count.Should().Be(1);
secretsResponse.ContainsKey("us-west-1/org/xpto/secretabc").Should().BeTrue();
secretsResponse["us-west-1/org/xpto/secretabc"].Should().Be("abc123");
}

[Fact]
public async Task GetSecretAsync_ReturnMultipleSecrets()
{
Expand Down
4 changes: 2 additions & 2 deletions test/Shared/TestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -394,7 +394,7 @@ public async Task<TestGrpcRequest<T>> CaptureGrpcRequestAsync<T>(Func<TClient, T
var task = operation(this.InnerClient);
if (task.IsFaulted)
{
// If the task throws, we want to bubble that up eaglerly.
// If the task throws, we want to bubble that up eagerly.
await task;
}

Expand Down

0 comments on commit b772daf

Please sign in to comment.