public async Task TestPushAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); IBlob testLayerBlob = Blobs.From("crepecake"); // Known digest for 'crepecake' DescriptorDigest testLayerBlobDigest = DescriptorDigest.FromHash( "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); IBlob testContainerConfigurationBlob = Blobs.From("12345"); DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.FromHash( "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5"); // Creates a valid image manifest. V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate(); expectedManifestTemplate.AddLayer(9, testLayerBlobDigest); expectedManifestTemplate.SetContainerConfiguration(5, testContainerConfigurationBlobDigest); // Pushes the BLOBs. RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "testimage") .SetAllowInsecureRegistries(true) .NewRegistryClient(); Assert.IsFalse( await registryClient.PushBlobAsync(testLayerBlobDigest, testLayerBlob, null, _ => { }).ConfigureAwait(false)); Assert.IsFalse( await registryClient.PushBlobAsync( testContainerConfigurationBlobDigest, testContainerConfigurationBlob, null, _ => { }).ConfigureAwait(false)); // Pushes the manifest. DescriptorDigest imageDigest = await registryClient.PushManifestAsync(expectedManifestTemplate, "latest").ConfigureAwait(false); // Pulls the manifest. V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); Assert.AreEqual(1, manifestTemplate.Layers.Count); Assert.AreEqual(testLayerBlobDigest, manifestTemplate.Layers[0].Digest); Assert.IsNotNull(manifestTemplate.GetContainerConfiguration()); Assert.AreEqual( testContainerConfigurationBlobDigest, manifestTemplate.GetContainerConfiguration().Digest); // Pulls the manifest by digest. V22ManifestTemplate manifestTemplateByDigest = await registryClient.PullManifestAsync <V22ManifestTemplate>(imageDigest.ToString()).ConfigureAwait(false); Assert.AreEqual( await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false), await Digests.ComputeJsonDigestAsync(manifestTemplateByDigest).ConfigureAwait(false)); }
public async Task TestPull_v22Async() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "gcr.io", "distroless/java").NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync("latest").ConfigureAwait(false); Assert.AreEqual(2, manifestTemplate.SchemaVersion); V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate)manifestTemplate; Assert.IsTrue(v22ManifestTemplate.Layers.Count > 0); }
public async Task TestCheck_existsAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); DescriptorDigest blobDigest = manifestTemplate.Layers[0].Digest; Assert.IsTrue(await registryClient.CheckBlobAsync(new BlobDescriptor(blobDigest)).ConfigureAwait(false)); }
public void SetUp() { mockEventHandlers = Mock.Of <IEventHandlers>(); v22manifestJsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); fakeManifestTemplate = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(v22manifestJsonFile); testManifestPusher = new ManifestPusher( new RegistryEndpointRequestProperties("someServerUrl", "someImageName"), fakeManifestTemplate, "test-image-tag", mockEventHandlers); }
public void TestRetrieveManifest_v22() { SystemPath cacheDirectory = temporaryFolder.NewFolder().ToPath(); SetupCachedMetadataV22(cacheDirectory); CacheStorageFiles cacheStorageFiles = new CacheStorageFiles(cacheDirectory); CacheStorageReader cacheStorageReader = new CacheStorageReader(cacheStorageFiles); V22ManifestTemplate manifestTemplate = (V22ManifestTemplate) cacheStorageReader .RetrieveMetadata(ImageReference.Of("test", "image", "tag")) .Get() .GetManifest(); Assert.AreEqual(2, manifestTemplate.SchemaVersion); }
public void TestFromJson() { // Loads the JSON string. SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); // Deserializes into a manifest JSON object. V22ManifestTemplate manifestJson = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(jsonFile); Assert.AreEqual( DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), manifestJson.GetContainerConfiguration().Digest); Assert.AreEqual(1000, manifestJson.GetContainerConfiguration().Size); Assert.AreEqual( DescriptorDigest.FromHash( "4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236"), manifestJson.Layers[0].Digest); Assert.AreEqual(1000_000, manifestJson.Layers[0].Size); }
public async Task TestWriteMetadata_v22Async() { SystemPath containerConfigurationJsonFile = Paths.Get( TestResources.GetResource("core/json/containerconfig.json").ToURI()); ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.ReadJsonFromFile <ContainerConfigurationTemplate>( containerConfigurationJsonFile); SystemPath manifestJsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); IBuildableManifestTemplate manifestTemplate = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(manifestJsonFile); ImageReference imageReference = ImageReference.Parse("image.reference/project/thing:tag"); await new CacheStorageWriter(cacheStorageFiles) .WriteMetadataAsync(imageReference, manifestTemplate, containerConfigurationTemplate).ConfigureAwait(false); SystemPath savedManifestPath = cacheRoot.Resolve("images/image.reference/project/thing!tag/manifest.json"); SystemPath savedConfigPath = cacheRoot.Resolve("images/image.reference/project/thing!tag/config.json"); Assert.IsTrue(Files.Exists(savedManifestPath)); Assert.IsTrue(Files.Exists(savedConfigPath)); V22ManifestTemplate savedManifest = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(savedManifestPath); Assert.AreEqual( "8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest.GetContainerConfiguration().Digest.GetHash()); ContainerConfigurationTemplate savedContainerConfig = JsonTemplateMapper.ReadJsonFromFile <ContainerConfigurationTemplate>(savedConfigPath); Assert.AreEqual("wasm", savedContainerConfig.Architecture); }
public void TestToJson() { // Loads the expected JSON string. SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); string expectedJson = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile)); // Creates the JSON object to serialize. V22ManifestTemplate manifestJson = new V22ManifestTemplate(); manifestJson.SetContainerConfiguration( 1000, DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")); manifestJson.AddLayer( 1000_000, DescriptorDigest.FromHash( "4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236")); // Serializes the JSON object. string result = JsonTemplateMapper.ToUtf8String(manifestJson); Assert.AreEqual(expectedJson, result); }