Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Registry #21

Merged
merged 81 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
eedc4db
Added IRepository
sammychinedu2ky May 2, 2023
1f78ac7
Added IRepository
sammychinedu2ky May 2, 2023
4aa30f3
made some changes
sammychinedu2ky May 4, 2023
bbd7b1e
made some changes
sammychinedu2ky May 4, 2023
fefed02
made some changes
sammychinedu2ky May 5, 2023
a1e1391
made some changes to some interfaces
sammychinedu2ky May 8, 2023
454d8dd
made some changes to some interfaces
sammychinedu2ky May 8, 2023
127aa30
made some changes to some interfaces
sammychinedu2ky May 8, 2023
7c1af78
made some changes to some interfaces
sammychinedu2ky May 8, 2023
3ba1fd1
Update Oras/Interfaces/Registry/IRepository.cs
sammychinedu2ky May 8, 2023
8efb2cb
created registry folder
sammychinedu2ky May 8, 2023
12f5162
made some changes to some interfaces
sammychinedu2ky May 8, 2023
6ccbc60
made some changes to some interfaces
sammychinedu2ky May 8, 2023
c28fdf7
Merge branch 'IRepository' into Registry
sammychinedu2ky May 8, 2023
3779cc9
adding extra features
sammychinedu2ky May 8, 2023
6b91cef
Merge branch 'main' into Registry
sammychinedu2ky May 8, 2023
42c61fe
adding extra features omo 😂
sammychinedu2ky May 9, 2023
f1b96ef
adding extra features
sammychinedu2ky May 9, 2023
b17da87
adding extra features
sammychinedu2ky May 11, 2023
4f2279e
added extra features
sammychinedu2ky May 11, 2023
0e97abd
added extra features
sammychinedu2ky May 11, 2023
082d57d
added extra features
sammychinedu2ky May 12, 2023
5b3b1b4
added extra features
sammychinedu2ky May 13, 2023
46cc242
added extra features
sammychinedu2ky May 15, 2023
d8448c0
added extra features
sammychinedu2ky May 15, 2023
72f7c46
added extra features
sammychinedu2ky May 15, 2023
ac4a1f7
testing the mic
sammychinedu2ky May 17, 2023
740c59c
little fix
sammychinedu2ky May 17, 2023
9de40d5
little fix
sammychinedu2ky May 17, 2023
2608197
little fix
sammychinedu2ky May 17, 2023
fb5a37d
little fix
sammychinedu2ky May 17, 2023
db94e93
little fix
sammychinedu2ky May 17, 2023
136bf9b
little fix
sammychinedu2ky May 18, 2023
5e64d87
Merge branch 'Test1' into Registry
sammychinedu2ky May 18, 2023
ea51603
created client code
sammychinedu2ky May 18, 2023
acf852b
created client code
sammychinedu2ky May 18, 2023
727022f
made some fixes
sammychinedu2ky May 18, 2023
5953bb8
added test
sammychinedu2ky May 19, 2023
5535e1d
added test
sammychinedu2ky May 19, 2023
500b78c
made some fixes
sammychinedu2ky May 19, 2023
2871411
added more test
sammychinedu2ky May 19, 2023
5a9060b
added more test
sammychinedu2ky May 19, 2023
fdca679
added more test
sammychinedu2ky May 19, 2023
69ff580
added more test
sammychinedu2ky May 20, 2023
92f534f
added more test
sammychinedu2ky May 20, 2023
af3150b
added more test
sammychinedu2ky May 22, 2023
e2ede17
added more test
sammychinedu2ky May 22, 2023
3553799
added more test
sammychinedu2ky May 22, 2023
4fdc000
added more test
sammychinedu2ky May 24, 2023
511ad16
added more test
sammychinedu2ky May 24, 2023
6a2fe7d
removed see
sammychinedu2ky May 25, 2023
6c74d76
formatted code
sammychinedu2ky May 25, 2023
ab4e8fa
fix: changed string to character
sammychinedu2ky May 25, 2023
cc6c64d
made some changes
sammychinedu2ky May 25, 2023
374ed59
fix: changed members name
sammychinedu2ky May 25, 2023
bc76e68
fix: changed members accessor
sammychinedu2ky May 25, 2023
778fd0a
fix: changed members accessor
sammychinedu2ky May 25, 2023
f19f348
fix: flash mode 🚀
sammychinedu2ky May 25, 2023
fb25cb6
added more test
sammychinedu2ky May 25, 2023
518c763
formatted code
sammychinedu2ky May 25, 2023
f13dbb5
made some changes
sammychinedu2ky May 26, 2023
8a21779
made some changes
sammychinedu2ky May 26, 2023
d40a0bf
made some changes
sammychinedu2ky May 26, 2023
61c68fb
added using statements
sammychinedu2ky May 26, 2023
17c3642
added extra test
sammychinedu2ky May 27, 2023
f629f18
added extra test
sammychinedu2ky May 27, 2023
bdce6be
changed test location
sammychinedu2ky May 27, 2023
f7a1f67
resolved an issue
sammychinedu2ky May 27, 2023
7a7dd66
resolved an issue
sammychinedu2ky May 27, 2023
aa8af80
resolved an issue
sammychinedu2ky May 27, 2023
7d4f49d
Update Oras/Remote/Repository.cs
sammychinedu2ky May 27, 2023
edf046c
resolved an issue
sammychinedu2ky May 27, 2023
74c2bee
resolved an issue
sammychinedu2ky May 27, 2023
a0818e5
Update Oras/Remote/Repository.cs
sammychinedu2ky May 27, 2023
27e1e7d
resolved an issue
sammychinedu2ky May 27, 2023
6a54ac4
resolved an issue
sammychinedu2ky May 27, 2023
2676ecb
resolved an issue
sammychinedu2ky May 27, 2023
ee0af2c
resolved an issue
sammychinedu2ky May 27, 2023
31595ef
resolved an issue
sammychinedu2ky May 27, 2023
3cf1bcf
resolved an issue
sammychinedu2ky May 27, 2023
3dc8dda
resolved an issue
sammychinedu2ky May 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Oras.Tests/Oras.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0-preview-20230223-05" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
150 changes: 150 additions & 0 deletions Oras.Tests/RemoteTest/RegistryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Moq;
using Moq.Protected;
using Oras.Remote;
using System.Net;
using System.Text.Json;
using System.Text.RegularExpressions;
using Xunit;

namespace Oras.Tests.RemoteTest
{
public class RegistryTest
{

public static HttpClient CustomClient(Func<HttpRequestMessage, CancellationToken, HttpResponseMessage> func)
{
var moqHandler = new Mock<DelegatingHandler>();
moqHandler.Protected().Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
).ReturnsAsync(func);
return new HttpClient(moqHandler.Object);
}

/// <summary>
/// TestRegistry_PingAsync tests the PingAsync method of the Registry class.
/// </summary>
/// <returns></returns>
[Fact]
public async Task TestRegistry_PingAsync()
{
var V2Implemented = true;
var func = (HttpRequestMessage req, CancellationToken cancellationToken) =>
{
var res = new HttpResponseMessage();
res.RequestMessage = req;

if (req.Method != HttpMethod.Get && req.RequestUri.AbsolutePath == $"/v2/")
{
res.StatusCode = HttpStatusCode.NotFound;
return res;
}

if (V2Implemented)
{
res.StatusCode = HttpStatusCode.OK;
return res;
}
else
{
res.StatusCode = HttpStatusCode.NotFound;
return res;
}
};
var registry = new Oras.Remote.Registry("localhost:5000");
registry.PlainHTTP = true;
registry.HttpClient = CustomClient(func);
var cancellationToken = new CancellationToken();
await registry.PingAsync(cancellationToken);
V2Implemented = false;
await Assert.ThrowsAnyAsync<Exception>(
async () => await registry.PingAsync(cancellationToken));
}

/// <summary>
/// TestRegistry_Repositories tests the ListRepositoriesAsync method of the Registry class.
/// </summary>
/// <returns></returns>
/// <exception cref="Exception"></exception>
[Fact]
public async Task TestRegistry_Repositories()
{
var repoSet = new List<List<string>>()
{
new() {"the", "quick", "brown", "fox"},
new() {"jumps", "over", "the", "lazy"},
new() {"dog"}
};
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
var func = (HttpRequestMessage req, CancellationToken cancellationToken) =>
{
var res = new HttpResponseMessage();
res.RequestMessage = req;
if (req.Method != HttpMethod.Get ||
req.RequestUri.AbsolutePath != "/v2/_catalog"
)
{
return new HttpResponseMessage(HttpStatusCode.NotFound);
}

var q = req.RequestUri.Query;
try
{
var n = int.Parse(Regex.Match(q, @"(?<=n=)\d+").Value);
if (n != 4) throw new Exception();
}
catch (Exception e)
{
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}

var repos = new List<string>();
var serverUrl = "http://localhost:5000";
var matched = Regex.Match(q, @"(?<=test=)\w+").Value;
switch (matched)
{
case "foo":
repos = repoSet[1];
res.Headers.Add("Link", $"<{serverUrl}/v2/_catalog?n=4&test=bar>; rel=\"next\"");
break;
case "bar":
repos = repoSet[2];
break;
default:
repos = repoSet[0];
res.Headers.Add("Link", $"</v2/_catalog?n=4&test=foo>; rel=\"next\"");
break;
}

var repositoryList = new ResponseTypes.RepositoryList
{
Repositories = repos.ToArray()
};
res.Content = new StringContent(JsonSerializer.Serialize(repositoryList));
return res;

};

var registry = new Oras.Remote.Registry("localhost:5000");
registry.PlainHTTP = true;
registry.HttpClient = CustomClient(func);
var cancellationToken = new CancellationToken();
registry.TagListPageSize = 4;



var index = 0;
await registry.Repositories("", async (string[] got) =>
{
if (index > 2)
{
throw new Exception($"Error out of range: {index}");
}

var repos = repoSet[index];
index++;
Assert.Equal(got, repos);
}, cancellationToken);
}
}
}
Loading