public void TestStoringArtifact()
        {
            //Cleanup test dir from old tests (if they failed before)
            TestUtils.CleanupDirIfExists(Path.Combine(projectDirectory, "TestData", "product"));

            var testPath = Path.Combine(projectDirectory, "TestData", "product", "ubuntu", "amd64", "1.1");

            //Create test artifact from a zip file
            var testFile = File.ReadAllBytes(Path.Combine(projectDirectory, "TestData", "test_zip.zip"));

            using var stream = new MemoryStream(testFile);
            var testZip = new ZipArchive(stream);

            var testArtifact = ReleaseArtifactMapper.ConvertToReleaseArtifact("product", "ubuntu",
                                                                              "amd64", "1.1", testZip);

            //Create the update test artifact from a zip file
            var testUpdateFile = File.ReadAllBytes(Path.Combine(projectDirectory, "TestData", "update_test_zip.zip"));

            using var updateStream = new MemoryStream(testUpdateFile);
            var testUpdateZip = new ZipArchive(updateStream);

            var testUpdateArtifact = ReleaseArtifactMapper.ConvertToReleaseArtifact("product", "ubuntu",
                                                                                    "amd64", "1.1", testUpdateZip);

            //Act

            //########################################
            //1. Store the first artifact -> product folder will be created
            //########################################
            fsReleaseArtifactRepository.StoreArtifact(testArtifact);

            //Assert if the directory and the unzipped files exist
            Assert.True(Directory.Exists(testPath));
            Assert.True(File.Exists(Path.Combine(testPath, "releaseNotes.json")));
            Assert.True(File.Exists(Path.Combine(testPath, "testprogram.exe")));
            Assert.True(File.Exists(Path.Combine(testPath, "deployment.json")));

            //########################################
            //2. Update the already existing product with the same artifact -> artifact folder & content will be updated
            //########################################
            fsReleaseArtifactRepository.StoreArtifact(testUpdateArtifact);

            //Assert if the directory and the unzipped files exist
            Assert.True(Directory.Exists(testPath));
            Assert.True(File.Exists(Path.Combine(testPath, "releaseNotes_update.json")));
            Assert.True(File.Exists(Path.Combine(testPath, "testprogram_update.exe")));
            Assert.True(File.Exists(Path.Combine(testPath, "deployment_update.json")));

            //Cleanup
            //Directory.Delete(Path.Combine(ProjectDirectory, "TestData", "product"), true);
        }
        public async Task StoreArtifact(string product, string os, string architecture, string version,
                                        IFormFile payload)
        {
            Logger.LogDebug("convert the uploaded payload to a ZIP archive");
            using var fileStream = payload.OpenReadStream();
            using var zipPayload = new ZipArchive(payload.OpenReadStream());

            var artifact =
                ReleaseArtifactMapper.ConvertToReleaseArtifact(product, os, architecture, version, zipPayload);

            await DirectoryLock.WaitAsync();

            //It's important to release the semaphore. try / finally block ensures a guaranteed release (also if the operation may crash)
            try
            {
                await Task.Run(() => FsReleaseArtifactRepository.StoreArtifact(artifact));
            }
            finally
            {
                DirectoryLock.Release();
            }
        }
示例#3
0
        public void ConvertToReleaseArtifactTest()
        {
            //Setup
            using var stream = new MemoryStream(testFile);
            var testZip = new ZipArchive(stream);

            var expectedArtifact = new ReleaseArtifact
            {
                ProductInformation = new ProductInformation
                {
                    Identifier   = "product",
                    Version      = new ProductVersion("1.1"),
                    Os           = "ubuntu",
                    Architecture = "amd64"
                },
                Payload = testZip
            };

            var testArtifact = ReleaseArtifactMapper.ConvertToReleaseArtifact("product", "ubuntu",
                                                                              "amd64", "1.1", testZip);

            testArtifact.Should().BeEquivalentTo(expectedArtifact);
        }