private static OciManifest DeserializeManifest(Stream stream) { try { return(OciSerialization.Deserialize <OciManifest>(stream)); } catch (Exception exception) { throw new InvalidModuleException("Unable to deserialize the module manifest.", exception); } }
public AndConstraint <MockRegistryAssertions> HaveModule(string tag, Stream expectedModuleContent) { using (new AssertionScope()) { this.Subject.ManifestTags.Should().ContainKey(tag, $"tag '{tag}' should exist"); string manifestDigest = this.Subject.ManifestTags[tag]; this.Subject.Manifests.Should().ContainKey(manifestDigest, $"tag '{tag}' resolves to digest '{manifestDigest}' that should exist"); var manifestBytes = this.Subject.Manifests[manifestDigest]; using var manifestStream = MockRegistryBlobClient.WriteStream(manifestBytes); var manifest = OciSerialization.Deserialize <OciManifest>(manifestStream); var config = manifest.Config; config.MediaType.Should().Be("application/vnd.ms.bicep.module.config.v1+json", "config media type should be correct"); config.Size.Should().Be(0, "config should be empty"); this.Subject.Blobs.Should().ContainKey(config.Digest, "config digest should exist"); var configBytes = this.Subject.Blobs[config.Digest]; configBytes.Should().BeEmpty("config should be empty"); manifest.Layers.Should().HaveCount(1, "modules should have a single layer"); var layer = manifest.Layers.Single(); layer.MediaType.Should().Be("application/vnd.ms.bicep.module.layer.v1+json", "layer media type should be correct"); this.Subject.Blobs.Should().ContainKey(layer.Digest); var layerBytes = this.Subject.Blobs[layer.Digest]; ((long)layerBytes.Length).Should().Be(layer.Size); var actual = MockRegistryBlobClient.WriteStream(layerBytes).FromJsonStream <JToken>(); var expected = expectedModuleContent.FromJsonStream <JToken>(); actual.Should().DeepEqual(expected, "module content should match"); } return(new(this)); }