Esempio n. 1
0
        public void ReadFromFileSystem_ValidJson_Succeeds()
        {
            var fileSystem = new MockFileSystem();
            var path       = fileSystem.Path.GetFullPath(VersionFile.FileName);

            fileSystem.AddFile(path, "{}");

            FluentActions.Invoking(() => VersionFile.ReadFromFileSystem(fileSystem)).Should().NotThrow();
        }
        public void Validate_ModifiedVersionFile_Succeeds()
        {
            this.fileSystem.AddFile(this.fileSystem.Path.GetFullPath(VersionFile.FileName), "modified");

            var fileToValidate = VersionFile.ReadFromFileSystem(this.fileSystem);

            Invoking(() => this.sut.Validate(fileToValidate)).Should()
            .Throw <InvalidModuleFileException>()
            .WithMessage($@"The file ""{fileToValidate.Path}"" is modified or outdated. Please regenerate the file to fix it.{Environment.NewLine}");
        }
Esempio n. 3
0
        public void ReadFromFileSystem_RootIsNotObject_ThrowsException()
        {
            var fileSystem = new MockFileSystem();
            var path       = fileSystem.Path.GetFullPath(VersionFile.FileName);

            fileSystem.AddFile(path, "[]");

            FluentActions.Invoking(() => VersionFile.ReadFromFileSystem(fileSystem)).Should()
            .Throw <BicepException>()
            .WithMessage($"The version file \"{path}\" must contain a JSON object at the root level.");
        }
Esempio n. 4
0
        public void ReadFromFileSystem_InvalidJson_ThrowsException()
        {
            var fileSystem = new MockFileSystem();
            var path       = fileSystem.Path.GetFullPath(VersionFile.FileName);

            fileSystem.AddFile(path, "######");

            FluentActions.Invoking(() => VersionFile.ReadFromFileSystem(fileSystem)).Should()
            .Throw <BicepException>()
            .WithMessage($"The version file \"{path}\" is not a valid JSON file.*");
        }
Esempio n. 5
0
        public void Validate_ModifiedVersionFile_Succeeds()
        {
            this.fileSystem.AddFile(this.fileSystem.Path.GetFullPath(VersionFile.FileName), @"{
  ""$schema"": ""https://aka.ms/bicep-registry-module-version-file-schema#"",
  ""version"": ""1.1"",
  ""pathFilters"": [
    ""./main.json""
  ]
}");

            var fileToValidate = VersionFile.ReadFromFileSystem(this.fileSystem);

            Invoking(() => this.sut.Validate(fileToValidate)).Should()
            .Throw <InvalidModuleException>()
            .WithMessage($@"The file ""{fileToValidate.Path}"" is modified or outdated. Please regenerate the file to fix it.{Environment.NewLine}");
        }
Esempio n. 6
0
            protected override int Invoke(InvocationContext context)
            {
                var valid = true;

                this.Logger.LogInformation("Validating module path...");
                valid &= Validate(context.Console, () => ValidateModulePath(this.FileSystem));

                this.Logger.LogInformation("Validating main Bicep file...");

                var bicepCliProxy = new BicepCliProxy(this.environmentProxy, this.processProxy, this.FileSystem, this.Logger, context.Console);
                var mainBicepFile = MainBicepFile.ReadFromFileSystem(this.FileSystem);

                // This also validates that the main Bicep file can be built without errors.
                var latestMainArmTemplateFile = MainArmTemplateFile.Generate(this.FileSystem, bicepCliProxy, mainBicepFile);
                var descriptionsValidator     = new DescriptionsValidator(this.Logger, latestMainArmTemplateFile);

                valid &= Validate(context.Console, () => mainBicepFile.ValidatedBy(descriptionsValidator));

                var testValidator       = new TestValidator(this.FileSystem, this.Logger, bicepCliProxy, latestMainArmTemplateFile);
                var jsonSchemaValidator = new JsonSchemaValidator(this.Logger);
                var diffValidator       = new DiffValidator(this.FileSystem, this.Logger, latestMainArmTemplateFile);

                this.Logger.LogInformation("Validating main Bicep test file...");
                valid &= Validate(context.Console, () => MainBicepTestFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(testValidator));

                this.Logger.LogInformation("Validating main ARM template file...");
                valid &= Validate(context.Console, () => MainArmTemplateFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(diffValidator));

                this.Logger.LogInformation("Validating metadata file...");
                valid &= Validate(context.Console, () => MetadataFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(jsonSchemaValidator));

                this.Logger.LogInformation("Validating README file...");
                valid &= Validate(context.Console, () => ReadmeFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(diffValidator));

                this.Logger.LogInformation("Validating version file...");
                valid &= Validate(context.Console, () => VersionFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(jsonSchemaValidator, diffValidator));

                return(valid ? 0 : 1);
            }
Esempio n. 7
0
        public void Validate_ValidVersionFile_Succeeds()
        {
            var fileToValidate = VersionFile.ReadFromFileSystem(this.fileSystem);

            Invoking(() => this.sut.Validate(fileToValidate)).Should().NotThrow();
        }