|
11 | 11 | using System.Net.Http.Json; |
12 | 12 | using System.Reflection; |
13 | 13 | using System.Text; |
| 14 | +using System.Text.Json; |
14 | 15 | using System.Threading; |
15 | 16 | using System.Threading.Tasks; |
16 | 17 | using System.Xml.Linq; |
17 | 18 | using Microsoft.Azure.Storage.Blob; |
18 | 19 | using Microsoft.Azure.WebJobs.Script.Config; |
| 20 | +using Microsoft.Azure.WebJobs.Script.Diagnostics.HealthChecks; |
19 | 21 | using Microsoft.Azure.WebJobs.Script.Management.Models; |
20 | 22 | using Microsoft.Azure.WebJobs.Script.Models; |
21 | 23 | using Microsoft.Azure.WebJobs.Script.WebHost; |
@@ -331,6 +333,43 @@ public async Task HealthCheck_AdminToken_Succeeds(string uri) |
331 | 333 | Assert.Equal("{\"status\":\"Healthy\"}", body); |
332 | 334 | } |
333 | 335 |
|
| 336 | + [Theory] |
| 337 | + [InlineData("/admin/health?expand=true", null)] |
| 338 | + [InlineData("/admin/health/live?expand=true", HealthCheckTags.Liveness)] |
| 339 | + [InlineData("/admin/health/ready?expand=true", HealthCheckTags.Readiness)] |
| 340 | + public async Task HealthCheck_AdminToken_ExpandSucceeds(string uri, string tag) |
| 341 | + { |
| 342 | + // token specified as bearer token |
| 343 | + HttpRequestMessage request = new(HttpMethod.Get, uri); |
| 344 | + string token = _fixture.Host.GenerateAdminJwtToken(); |
| 345 | + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); |
| 346 | + HttpResponseMessage response = await _fixture.Host.HttpClient.SendAsync(request); |
| 347 | + Assert.Equal(HttpStatusCode.OK, response.StatusCode); |
| 348 | + |
| 349 | + // Not doing a deep validation of the response, just ensuring we get the correct tags. |
| 350 | + // The full response body is validated in other tests. |
| 351 | + using Stream stream = await response.Content.ReadAsStreamAsync(); |
| 352 | + JsonDocument json = await JsonDocument.ParseAsync(stream); |
| 353 | + JsonElement entries = json.RootElement.GetProperty("entries"); |
| 354 | + |
| 355 | + if (string.IsNullOrEmpty(tag)) |
| 356 | + { |
| 357 | + Assert.NotEmpty(entries.EnumerateObject()); |
| 358 | + } |
| 359 | + else |
| 360 | + { |
| 361 | + bool atLeastOne = false; |
| 362 | + foreach (JsonProperty entry in entries.EnumerateObject()) |
| 363 | + { |
| 364 | + atLeastOne = true; |
| 365 | + HashSet<string> tags = entry.Value.GetProperty("tags").Deserialize<HashSet<string>>(); |
| 366 | + Assert.Contains(tag, tags); |
| 367 | + } |
| 368 | + |
| 369 | + Assert.True(atLeastOne, "Expected at least one entry to have the specified tag."); |
| 370 | + } |
| 371 | + } |
| 372 | + |
334 | 373 | [Theory] |
335 | 374 | [InlineData("/admin/health")] |
336 | 375 | [InlineData("/admin/health/live")] |
|
0 commit comments