Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Pan <[email protected]>
  • Loading branch information
Patrick Pan committed Nov 19, 2024
1 parent 7809549 commit c7e4418
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/OrasProject.Oras.Tests/Remote/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,7 @@ public async Task ManifestStore_FetchAsync_ManifestUnknown()
{
return new HttpResponseMessage(HttpStatusCode.MethodNotAllowed);
}
if (req.Headers.TryGetValues("Accept", out IEnumerable<string>? values) &&
!values.Contains(MediaType.ImageManifest))
if (req.Headers.TryGetValues("Accept", out IEnumerable<string>? values) && !values.Contains(MediaType.ImageManifest))
{
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
Expand Down Expand Up @@ -2045,16 +2044,15 @@ public async Task ManifestStore_TagAsync()
[Fact]
public async Task ManifestStore_PushReferenceAsync()
{
var manifest = Encoding.UTF8.GetBytes($@"{{""layers"": []}}");
var indexStr = $@"{{""manifests"":[{{""mediaType"": ""{MediaType.ImageManifest}"", ""digest"": ""{ComputeSHA256(manifest)}"", ""size"": {manifest.Length}}}]}}";
var index = Encoding.UTF8.GetBytes(indexStr);
var index = RandomIndex();
var indexBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(index));
var indexDesc = new Descriptor
{
MediaType = MediaType.ImageIndex,
Digest = ComputeSHA256(index),
Size = index.Length
Digest = ComputeSHA256(indexBytes),
Size = indexBytes.Length
};
var gotIndex = new byte[index.Length];
var gotIndex = new byte[indexBytes.Length];
var reference = "foobar";

var func = async (HttpRequestMessage req, CancellationToken cancellationToken) =>
Expand Down Expand Up @@ -2092,8 +2090,8 @@ public async Task ManifestStore_PushReferenceAsync()
});
var cancellationToken = new CancellationToken();
var store = new ManifestStore(repo);
await store.PushAsync(indexDesc, new MemoryStream(index), reference, cancellationToken);
Assert.Equal(index, gotIndex);
await store.PushAsync(indexDesc, new MemoryStream(indexBytes), reference, cancellationToken);
Assert.Equal(indexBytes, gotIndex);
}

/// <summary>
Expand Down

0 comments on commit c7e4418

Please sign in to comment.