public void BasicTemplateNoErrors(NameChecking subject)
        {
            var json   = ReadAllText(Combine("Examples", "basic.json"));
            var errors = subject.CheckTemplate(json);

            errors.Should().BeEmpty();
        }
        [InlineAutoMoqData("[concat(uniquestring(resourceGroup().id), 'standardsa')]")] // Ignoring function calls currently
        public void StorageNameOk(string name, NameChecking subject)
        {
            var json = ReadAllText(Combine("Examples", "storage-basic.json"))
                       .Replace("storagename", name);

            var errors = subject.CheckTemplate(json);

            errors.Should().BeEmpty();
        }
        public void IgnoreLongNameUnknownResourceType(NameChecking subject)
        {
            var json = ReadAllText(Combine("Examples", "storage-basic.json"))
                       .Replace("storagename", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")
                       .Replace("Microsoft.Storage/storageAccounts", "Durwella.Cloud/Unknown");

            var errors = subject.CheckTemplate(json);

            errors.Should().BeEmpty();
        }
        public void VariableFunctionIntegration(JintFunctionEvaluation subject, NameChecking nameChecking)
        {
            var path = Path.Combine("Examples", "storage-variable-name.json");
            var text = File.ReadAllText(path);

            var output = subject.EvaluateAndReplaceFunctions(text);

            output.Should().Contain("\"name\": \"my_storage\",");
            nameChecking.CheckTemplate(output).Should().BeEmpty();
        }
        public void VariableTags(JintFunctionEvaluation subject, NameChecking nameChecking)
        {
            var path = Path.Combine("Examples", "variable-tags.json");
            var text = File.ReadAllText(path);

            var output = subject.EvaluateAndReplaceFunctions(text);

            output.Should().Contain("\"tag1\": \"the 1st\",");
            output.Should().Contain("\"tag2\": \"the 2nd\"");
            nameChecking.CheckTemplate(output).Should().BeEmpty();
        }
        public void StorageNameTooShort(NameChecking subject)
        {
            var name = "a1";
            var json = ReadAllText(Combine("Examples", "storage-basic.json"))
                       .Replace("storagename", name);

            var errors = subject.CheckTemplate(json);

            errors.Should().HaveCount(1);
            var error = errors.Single();

            error.LineNumber.Should().Be(8);
            error.Message.Should().Contain($"'{name}' is too short");
        }
Exemple #7
0
        static void Main(string[] args)
        {
#if DEBUG
            WriteLine("Hello from Durwella.Azure.ArmTesting.Build!");
#endif
            if (args.Length == 0)
            {
                Error.WriteLine("Durwella.Azure.ArmTesting.Build requires a command line argument of the project path.");
                return;
            }
            var projectPath = args[0];
#if DEBUG
            WriteLine($"Project Path: {projectPath}");
#endif
            Write("  ARM Templates: ");
            var armTemplateEnumeration = _container.GetInstance <IArmTemplateEnumeration>();
            var armTemplates           = armTemplateEnumeration.EnumerateArmTemplatePaths(projectPath);
            if (armTemplates.Any())
            {
                WriteLine();
            }
            else
            {
                WriteLine("(none)");
            }
            foreach (var armTemplate in armTemplates)
            {
                WriteLine($"  - {armTemplate}");
                // HACK: Quick wire up of name checking
                var nameChecking = new NameChecking();
                var json         = File.ReadAllText(armTemplate);
                // Evaluated functions in arm template like "[concat('foo', 'bar')]"
                var functionEvaluation = _container.GetInstance <IArmFunctionEvaluation>();
                json = functionEvaluation.EvaluateAndReplaceFunctions(json);
                var errors = nameChecking.CheckTemplate(json)
                             .Select(e => new ArmTemplateError(armTemplate, e));
                foreach (var error in errors)
                {
                    WriteLine(error);
                }
            }
        }