Exemple #1
0
        public async Task SubstituteVariablesAndUploadTarGzipArchives()
        {
            const string packageId        = "TestTarGzipPackage";
            const string packageVersion   = "0.0.1";
            const string packageExtension = "tar.gz";
            var          fileName         = $"{packageId}.{packageVersion}.{packageExtension}";

            var packageOptions = new List <S3PackageOptions>
            {
                new S3PackageOptions
                {
                    StorageClass = "STANDARD",
                    CannedAcl    = "private",
                    StructuredVariableSubstitutionPatterns = "*.json",
                    BucketKeyBehaviour = BucketKeyBehaviourType.Filename,
                }
            };

            var variables = new CalamariVariables();

            variables.Set("Property1:Property2:Value", "InjectedValue");

            var packageFilePath = TestEnvironment.GetTestPath("AWS", "S3", "CompressedPackages", fileName);

            var prefix = UploadEntireCompressedPackage(packageFilePath, packageId, packageVersion, packageOptions, variables);

            await Validate(async client =>
            {
                var file              = await client.GetObjectAsync(bucketName, $"{prefix}{fileName}");
                var tempFileName      = Path.GetTempFileName();
                var tempDirectoryName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(tempFileName));
                try
                {
                    using (var fs = File.OpenWrite(tempFileName))
                    {
                        await file.ResponseStream.CopyToAsync(fs);
                    }

                    var log       = new InMemoryLog();
                    var extractor = new TarGzipPackageExtractor(log);
                    extractor.Extract(tempFileName, tempDirectoryName);
                    var text = File.ReadAllText(Path.Combine(tempDirectoryName, "file.json"));
                    JObject.Parse(text)["Property1"]["Property2"]["Value"].ToString().Should().Be("InjectedValue");
                }
                finally
                {
                    File.Delete(tempFileName);
                    Directory.Delete(tempDirectoryName, true);
                }
            });
        }
        //Latest version of SharpCompress throws an exception if a symbolic link is encountered and we haven't provided a handler for it.
        public void ExtractIgnoresSymbolicLinks()
        {
            var log      = new InMemoryLog();
            var fileName = GetFixtureResource("Samples", string.Format("{0}.{1}.{2}", PackageId, "1.0.0.0-symlink", "tar.gz"));

            var extractor = new TarGzipPackageExtractor(log);
            var targetDir = GetTargetDir(typeof(TarGzipPackageExtractor), fileName);

            extractor.Extract(fileName, targetDir);

            //If we get this far and an exception hasn't been thrown, the test has served it's purpose'

            //If the symbolic link actually exists, someone has implimented it but hasn't updated/deleted this test
            var symlink = Path.Combine(targetDir, "octopus-sample", "link-to-sample");

            Assert.That(File.Exists(symlink), Is.False, $"Symbolic link exists, please update this test.");

            log.StandardOut.Should().ContainMatch("Cannot create symbolic link*");
        }