|
18 | 18 | using Microsoft.Azure.WebJobs.Script.Workers.SharedMemoryDataTransfer;
|
19 | 19 | using Microsoft.Extensions.Logging;
|
20 | 20 | using Microsoft.Extensions.Logging.Abstractions;
|
| 21 | +using Microsoft.WebJobs.Script.Tests; |
21 | 22 | using Newtonsoft.Json.Linq;
|
22 | 23 | using Xunit;
|
23 | 24 |
|
@@ -316,6 +317,94 @@ public async Task ToRpcInvocationRequest_MultipleInputBindings()
|
316 | 317 | Assert.True(result.TriggerMetadata.ContainsKey("query"));
|
317 | 318 | }
|
318 | 319 |
|
| 320 | + [Fact] |
| 321 | + public async Task ToRpc_Http() |
| 322 | + { |
| 323 | + var rpcHttp = await CreateTestRpcHttp(); |
| 324 | + |
| 325 | + Assert.Equal("http://local/test?a=b", rpcHttp.Url); |
| 326 | + Assert.Equal("test value", rpcHttp.Headers["test-header"]); |
| 327 | + Assert.Equal("b", rpcHttp.Query["a"]); |
| 328 | + Assert.Equal("test body", rpcHttp.Body.String); |
| 329 | + } |
| 330 | + |
| 331 | + [Fact] |
| 332 | + public async Task ToRpc_Http_WithProxy() |
| 333 | + { |
| 334 | + // Specify that we're using proxies. |
| 335 | + var rpcHttp = await CreateTestRpcHttp(new Dictionary<string, string>() { { "HttpUri", "something" } }); |
| 336 | + |
| 337 | + // everything should come back empty |
| 338 | + Assert.Empty(rpcHttp.Url); |
| 339 | + Assert.Empty(rpcHttp.Headers); |
| 340 | + Assert.Empty(rpcHttp.Query); |
| 341 | + Assert.Null(rpcHttp.Body); |
| 342 | + } |
| 343 | + |
| 344 | + private async Task<RpcHttp> CreateTestRpcHttp(IDictionary<string, string> capabilities = null) |
| 345 | + { |
| 346 | + var logger = new TestLogger("test"); |
| 347 | + GrpcCapabilities grpcCapabilities = new GrpcCapabilities(logger); |
| 348 | + if (capabilities is not null) |
| 349 | + { |
| 350 | + grpcCapabilities.UpdateCapabilities(capabilities); |
| 351 | + } |
| 352 | + |
| 353 | + var headers = new HeaderDictionary(); |
| 354 | + headers.Add("test-header", "test value"); |
| 355 | + var request = HttpTestHelpers.CreateHttpRequest("POST", "http://local/test?a=b", headers: headers, body: "test body"); |
| 356 | + |
| 357 | + var bindingData = new Dictionary<string, object> |
| 358 | + { |
| 359 | + { "req", request }, |
| 360 | + }; |
| 361 | + |
| 362 | + var inputs = new List<(string Name, DataType Type, object Val)> |
| 363 | + { |
| 364 | + ("req", DataType.String, request), |
| 365 | + }; |
| 366 | + |
| 367 | + var invocationContext = new ScriptInvocationContext() |
| 368 | + { |
| 369 | + ExecutionContext = new ExecutionContext() |
| 370 | + { |
| 371 | + InvocationId = Guid.NewGuid(), |
| 372 | + FunctionName = "Test", |
| 373 | + }, |
| 374 | + BindingData = bindingData, |
| 375 | + Inputs = inputs, |
| 376 | + ResultSource = new TaskCompletionSource<ScriptInvocationResult>(), |
| 377 | + Logger = logger, |
| 378 | + AsyncExecutionContext = System.Threading.ExecutionContext.Capture() |
| 379 | + }; |
| 380 | + |
| 381 | + var functionMetadata = new FunctionMetadata |
| 382 | + { |
| 383 | + Name = "Test" |
| 384 | + }; |
| 385 | + |
| 386 | + var httpTriggerBinding = new BindingMetadata |
| 387 | + { |
| 388 | + Name = "req", |
| 389 | + Type = "httpTrigger", |
| 390 | + Direction = BindingDirection.In, |
| 391 | + Raw = new JObject() |
| 392 | + }; |
| 393 | + |
| 394 | + functionMetadata.Bindings.Add(httpTriggerBinding); |
| 395 | + invocationContext.FunctionMetadata = functionMetadata; |
| 396 | + |
| 397 | + var result = await invocationContext.ToRpcInvocationRequest(logger, grpcCapabilities, isSharedMemoryDataTransferEnabled: false, _sharedMemoryManager); |
| 398 | + var resultHttp = result.InputData[0].Data.Http; |
| 399 | + Assert.Equal(1, result.TriggerMetadata.Count); |
| 400 | + Assert.Same(resultHttp, result.TriggerMetadata["req"].Http); |
| 401 | + |
| 402 | + Assert.Equal(1, result.InputData.Count); |
| 403 | + Assert.Equal("req", result.InputData[0].Name); |
| 404 | + |
| 405 | + return resultHttp; |
| 406 | + } |
| 407 | + |
319 | 408 | [Fact]
|
320 | 409 | public void TestSetRetryContext_NoRetry()
|
321 | 410 | {
|
|
0 commit comments