Skip to content

Commit

Permalink
API Endpoint change: prepare_read URI (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-paidis-sonarsource authored Jul 19, 2024
1 parent 544d5de commit f278d0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async Task DownloadCache_AutomaticallyDeduceBaseBranch(string provider, s
using var environment = new EnvironmentVariableScope().SetVariable(variableName, "branch-42");
const string organization = "org42";
using var stream = new MemoryStream();
var handler = MockHttpHandler("http://myhost:222/v1/sensor_cache/prepare_read?organization=org42&project=project-key&branch=branch-42", "https://www.ephemeralUrl.com", stream);
var handler = MockHttpHandler("http://myhost:222/sensor-cache/prepare-read?organization=org42&project=project-key&branch=branch-42", "https://www.ephemeralUrl.com", stream);
var sut = CreateServer(MockIDownloader("http://myhost:222"), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, null, organization, Token);

Expand All @@ -210,7 +210,7 @@ public async Task DownloadCache_UserInputSupersedesAutomaticDetection(string var
using var environment = new EnvironmentVariableScope().SetVariable(variableName, "wrong-branch");
const string organization = "org42";
using var stream = new MemoryStream();
var handler = MockHttpHandler("http://myhost:222/v1/sensor_cache/prepare_read?organization=org42&project=project-key&branch=project-branch", "https://www.ephemeralUrl.com", stream);
var handler = MockHttpHandler("http://myhost:222/sensor-cache/prepare-read?organization=org42&project=project-key&branch=project-branch", "https://www.ephemeralUrl.com", stream);
var sut = CreateServer(MockIDownloader("http://myhost:222"), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch, organization, Token);

Expand All @@ -221,9 +221,9 @@ public async Task DownloadCache_UserInputSupersedesAutomaticDetection(string var
}

[TestMethod]
[DataRow("http://cacheBaseUrl:222", "http://cachebaseurl:222/v1/sensor_cache/prepare_read?organization=org42&project=project-key&branch=project-branch")]
[DataRow("http://cacheBaseUrl:222/", "http://cachebaseurl:222/v1/sensor_cache/prepare_read?organization=org42&project=project-key&branch=project-branch")]
[DataRow("http://cacheBaseUrl:222/sonar/", "http://cachebaseurl:222/sonar/v1/sensor_cache/prepare_read?organization=org42&project=project-key&branch=project-branch")]
[DataRow("http://cacheBaseUrl:222", "http://cachebaseurl:222/sensor-cache/prepare-read?organization=org42&project=project-key&branch=project-branch")]
[DataRow("http://cacheBaseUrl:222/", "http://cachebaseurl:222/sensor-cache/prepare-read?organization=org42&project=project-key&branch=project-branch")]
[DataRow("http://cacheBaseUrl:222/sonar/", "http://cachebaseurl:222/sonar/sensor-cache/prepare-read?organization=org42&project=project-key&branch=project-branch")]
public async Task DownloadCache_RequestUrl(string cacheBaseUrl, string cacheFullUrl)
{
var logger = new TestLogger();
Expand All @@ -247,7 +247,7 @@ public async Task DownloadCache_CacheHit(string tokenKey)
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
using var stream = CreateCacheStream(new SensorCacheEntry { Key = "key", Data = ByteString.CopyFromUtf8("value") });
var handler = MockHttpHandler(cacheFullUrl, "https://www.ephemeralUrl.com", stream);
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
Expand All @@ -266,7 +266,7 @@ public async Task DownloadCache_PrepareRead_UnsuccessfulResponse()
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
var handler = MockHttpHandler(cacheFullUrl, "irrelevant", HttpStatusCode.Forbidden);
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch, Organization, Token);
Expand All @@ -283,7 +283,7 @@ public async Task DownloadCache_PrepareRead_EmptyResponse()
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
var handler = MockHttpHandler(cacheFullUrl, string.Empty);
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch, Organization, Token);
Expand All @@ -300,7 +300,7 @@ public async Task DownloadCache_PrepareRead_CacheDisabled()
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
var handler = MockHttpHandler(cacheFullUrl, $@"{{ ""enabled"": ""false"", ""url"":""https://www.sonarsource.com"" }}");
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch, Organization, Token);
Expand All @@ -318,7 +318,7 @@ public async Task DownloadCache_PrepareRead_CacheEnabledButUrlMissing()
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
var handler = MockHttpHandler(cacheFullUrl, $@"{{ ""enabled"": ""true"" }}");
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch, Organization, Token);
Expand All @@ -335,7 +335,7 @@ public async Task DownloadCache_ThrowException()
{
var logger = new TestLogger();
const string cacheBaseUrl = "https://www.cacheBaseUrl.com";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/v1/sensor_cache/prepare_read?organization={Organization}&project=project-key&branch=project-branch";
var cacheFullUrl = $"https://www.cacheBaseUrl.com/sensor-cache/prepare-read?organization={Organization}&project=project-key&branch=project-branch";
using var stream = new MemoryStream([42, 42]); // this is a random byte array that fails deserialization
var handler = MockHttpHandler(cacheFullUrl, "https://www.ephemeralUrl.com", stream);
var sut = CreateServer(MockIDownloader(cacheBaseUrl), handler: handler, logger: logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override void Dispose(bool disposing)

private async Task<Uri> DownloadEphemeralUrl(string organization, string projectKey, string branch, string token, string cacheBaseUrl)
{
var uri = new Uri(WebUtils.CreateUri(cacheBaseUrl), WebUtils.Escape("v1/sensor_cache/prepare_read?organization={0}&project={1}&branch={2}", organization, projectKey, branch));
var uri = new Uri(WebUtils.CreateUri(cacheBaseUrl), WebUtils.Escape("sensor-cache/prepare-read?organization={0}&project={1}&branch={2}", organization, projectKey, branch));
using var request = new HttpRequestMessage(HttpMethod.Get, uri);
request.Headers.Add("Authorization", $"Bearer {token}");
logger.LogDebug(Resources.MSG_Processing_PullRequest_RequestPrepareRead, uri);
Expand Down

0 comments on commit f278d0c

Please sign in to comment.