-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide integration tests for other operations (#1356)
- Loading branch information
1 parent
457d354
commit 640e185
Showing
19 changed files
with
199 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variables: | ||
- name: Agent.Scraper.Prometheus.ScrapeUri | ||
value: metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Promitor.Tests.Integration.Clients | ||
{ | ||
public class ScraperClient: AgentClient | ||
public class ScraperClient : AgentClient | ||
{ | ||
public ScraperClient(IConfiguration configuration, ILogger logger) | ||
:base("Scraper", "Agents:Scraper:BaseUrl", configuration,logger) | ||
{ | ||
} | ||
|
||
public async Task<HttpResponseMessage> GetRuntimeConfigurationAsync() | ||
{ | ||
return await GetAsync("/api/v1/configuration/runtime"); | ||
} | ||
|
||
public async Task<HttpResponseMessage> GetMetricDeclarationAsync() | ||
{ | ||
return await GetAsync("/api/v1/configuration/metric-declaration"); | ||
} | ||
|
||
public async Task<HttpResponseMessage> ScrapeAsync() | ||
{ | ||
var scrapeUri = Configuration["Agents:Scraper:Prometheus:ScrapeUri"]; | ||
return await GetAsync($"/{scrapeUri}"); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Promitor.Tests.Integration/Extensions/HttpResponseHeadersExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using GuardNet; | ||
|
||
namespace Promitor.Tests.Integration.Extensions | ||
{ | ||
public static class HttpResponseHeadersExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the first or default value for a given HTTP header | ||
/// </summary> | ||
public static string GetFirstOrDefaultHeaderValue(this HttpResponseHeaders headers, string headerName) | ||
{ | ||
Guard.NotNull(headers, nameof(headers)); | ||
Guard.NotNullOrWhitespace(headerName, nameof(headerName)); | ||
|
||
return headers.GetValues(headerName)?.FirstOrDefault(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Promitor.Tests.Integration/Services/Scraper/ConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using Promitor.Agents.Core; | ||
using Promitor.Tests.Integration.Clients; | ||
using Promitor.Tests.Integration.Extensions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Promitor.Agents.Scraper.Configuration; | ||
|
||
namespace Promitor.Tests.Integration.Services.Scraper | ||
{ | ||
public class ConfigurationTests : ScraperIntegrationTest | ||
{ | ||
public ConfigurationTests(ITestOutputHelper testOutput) | ||
: base(testOutput) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task RuntimeConfiguration_Get_ReturnsOk() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.GetRuntimeConfigurationAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
var rawPayload = await response.Content.ReadAsStringAsync(); | ||
Assert.NotEmpty(rawPayload); | ||
var metrics = JsonConvert.DeserializeObject<ScraperRuntimeConfiguration>(rawPayload); | ||
Assert.NotNull(metrics); | ||
} | ||
|
||
[Fact] | ||
public async Task RuntimeConfiguration_Get_ReturnsVersionHeader() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.GetRuntimeConfigurationAsync(); | ||
|
||
// Assert | ||
Assert.True(response.Headers.Contains(HttpHeaders.AgentVersion)); | ||
Assert.Equal(ExpectedVersion, response.Headers.GetFirstOrDefaultHeaderValue(HttpHeaders.AgentVersion)); | ||
} | ||
|
||
[Fact] | ||
public async Task MetricDeclaration_Get_ReturnsOk() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.GetMetricDeclarationAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task MetricDeclaration_Get_ReturnsVersionHeader() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.GetMetricDeclarationAsync(); | ||
|
||
// Assert | ||
Assert.True(response.Headers.Contains(HttpHeaders.AgentVersion)); | ||
Assert.Equal(ExpectedVersion, response.Headers.GetFirstOrDefaultHeaderValue(HttpHeaders.AgentVersion)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Promitor.Tests.Integration/Services/Scraper/MetricSinksTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Promitor.Agents.Core; | ||
using Promitor.Tests.Integration.Clients; | ||
using Promitor.Tests.Integration.Extensions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Promitor.Tests.Integration.Services.Scraper | ||
{ | ||
public class MetricSinksTests : ScraperIntegrationTest | ||
{ | ||
public MetricSinksTests(ITestOutputHelper testOutput) | ||
: base(testOutput) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task Prometheus_Scrape_ReturnsOk() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.ScrapeAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task Prometheus_Scrape_Get_ReturnsVersionHeader() | ||
{ | ||
// Arrange | ||
var scraperClient = new ScraperClient(Configuration, Logger); | ||
|
||
// Act | ||
var response = await scraperClient.ScrapeAsync(); | ||
|
||
// Assert | ||
Assert.True(response.Headers.Contains(HttpHeaders.AgentVersion)); | ||
Assert.Equal(ExpectedVersion, response.Headers.GetFirstOrDefaultHeaderValue(HttpHeaders.AgentVersion)); | ||
} | ||
} | ||
} |
Oops, something went wrong.