Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comonize AzResourceTypeProvider logic #2222

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bicep.Cli.IntegrationTests/DecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static (IEnumerable<string> outputLines, IEnumerable<string> errorLines,
{
var (output, error, result) = TextWriterHelper.InvokeWriterAction((outputWriter, errorWriter) =>
{
var program = new Program(TestResourceTypeProvider.Create(), outputWriter, errorWriter, BicepTestConstants.DevAssemblyFileVersion);
var program = new Program(TestTypeHelper.CreateEmptyProvider(), outputWriter, errorWriter, BicepTestConstants.DevAssemblyFileVersion);

return program.Run(args);
});
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Cli.IntegrationTests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ProgramTests

private static Program CreateProgram(TextWriter outputWriter, TextWriter errorWriter)
{
return new Program(TestResourceTypeProvider.Create(), outputWriter, errorWriter, BicepTestConstants.DevAssemblyFileVersion);
return new Program(TestTypeHelper.CreateEmptyProvider(), outputWriter, errorWriter, BicepTestConstants.DevAssemblyFileVersion);
}

[TestMethod]
Expand Down Expand Up @@ -337,7 +337,7 @@ public void LockedOutputFileShouldProduceExpectedError()
private static IEnumerable<string> GetAllDiagnostics(string bicepFilePath)
{
var syntaxTreeGrouping = SyntaxTreeGroupingBuilder.Build(new FileResolver(), new Workspace(), PathHelper.FilePathToFileUrl(bicepFilePath));
var compilation = new Compilation(TestResourceTypeProvider.Create(), syntaxTreeGrouping);
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), syntaxTreeGrouping);

var output = new List<string>();
foreach (var (syntaxTree, diagnostics) in compilation.GetAllDiagnosticsBySyntaxTree())
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Program(IResourceTypeProvider resourceTypeProvider, TextWriter outputWrit
public static int Main(string[] args)
{
BicepDeploymentsInterop.Initialize();
var program = new Program(new AzResourceTypeProvider(), Console.Out, Console.Error, ThisAssembly.AssemblyFileVersion);
var program = new Program(AzResourceTypeProvider.CreateWithAzTypes(), Console.Out, Console.Error, ThisAssembly.AssemblyFileVersion);
return program.Run(args);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Core.IntegrationTests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ param inputb string
",
};

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var diagnosticsByFile = compilation.GetAllDiagnosticsBySyntaxTree().ToDictionary(kvp => kvp.Key.FileUri, kvp => kvp.Value);
var success = diagnosticsByFile.Values.SelectMany(x => x).All(d => d.Level != DiagnosticLevel.Error);

Expand Down Expand Up @@ -156,7 +156,7 @@ param inputb string
",
};

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var diagnosticsByFile = compilation.GetAllDiagnosticsBySyntaxTree().ToDictionary(kvp => kvp.Key.FileUri, kvp => kvp.Value);
var success = diagnosticsByFile.Values.SelectMany(x => x).All(d => d.Level != DiagnosticLevel.Error);

Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Multiline_strings_should_parse_correctly(string newlineSequence)

private EmitResult EmitTemplate(SyntaxTreeGrouping syntaxTreeGrouping, string filePath, string assemblyFileVersion)
{
var compilation = new Compilation(TestResourceTypeProvider.Create(), syntaxTreeGrouping);
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), syntaxTreeGrouping);
var emitter = new TemplateEmitter(compilation.GetEntrypointSemanticModel(), assemblyFileVersion);

using var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
Expand All @@ -138,7 +138,7 @@ private EmitResult EmitTemplate(SyntaxTreeGrouping syntaxTreeGrouping, string fi

private EmitResult EmitTemplate(SyntaxTreeGrouping syntaxTreeGrouping, MemoryStream memoryStream, string assemblyFileVersion)
{
var compilation = new Compilation(TestResourceTypeProvider.Create(), syntaxTreeGrouping);
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), syntaxTreeGrouping);
var emitter = new TemplateEmitter(compilation.GetEntrypointSemanticModel(), assemblyFileVersion);

TextWriter tw = new StreamWriter(memoryStream);
Expand Down
18 changes: 9 additions & 9 deletions src/Bicep.Core.IntegrationTests/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile.Values.SelectMany(x => x).Should().BeEmpty();
Expand Down Expand Up @@ -104,7 +104,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
Expand Down Expand Up @@ -159,7 +159,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
Expand Down Expand Up @@ -222,7 +222,7 @@ param inputb string
SetupFileReaderMock(mockFileResolver, mainFileUri, mainFileContents, null);
mockFileResolver.Setup(x => x.TryResolveModulePath(mainFileUri, "modulea.bicep")).Returns((Uri?)null);

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingBuilder.Build(mockFileResolver.Object, new Workspace(), mainFileUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingBuilder.Build(mockFileResolver.Object, new Workspace(), mainFileUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainFileUri].Should().HaveDiagnostics(new[] {
Expand Down Expand Up @@ -295,7 +295,7 @@ param inputb int
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile.Values.SelectMany(x => x).Should().BeEmpty();
Expand All @@ -319,22 +319,22 @@ param inputb int

// Confirming hashes equal individual template hashes
ModuleTemplateHashValidator(
new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
{
[moduleAUri] = files[moduleAUri]
},
moduleAUri)), moduleATemplateHash);

ModuleTemplateHashValidator(
new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
{
[moduleBUri] = files[moduleBUri],
[moduleCUri] = files[moduleCUri]
},
moduleBUri)), moduleBTemplateHash);

ModuleTemplateHashValidator(
new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateForFiles(new Dictionary<Uri, string>
{
[moduleCUri] = files[moduleCUri]
},
Expand Down Expand Up @@ -364,7 +364,7 @@ param inputb string
SetupFileReaderMock(mockFileResolver, moduleAUri, null, x => x.ErrorOccurredReadingFile("Mock read failure!"));
mockFileResolver.Setup(x => x.TryResolveModulePath(mainUri, "modulea.bicep")).Returns(moduleAUri);

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingBuilder.Build(mockFileResolver.Object, new Workspace(), mainUri));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingBuilder.Build(mockFileResolver.Object, new Workspace(), mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
Expand Down
28 changes: 14 additions & 14 deletions src/Bicep.Core.IntegrationTests/NestedResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void NestedResources_symbols_are_bound()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();

model.GetAllDiagnostics().Should().BeEmpty();
Expand Down Expand Up @@ -86,7 +86,7 @@ public void NestedResources_resource_can_contain_property_called_resource()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();

// The property "resource" is not allowed ...
Expand Down Expand Up @@ -144,7 +144,7 @@ public void NestedResources_valid_resource_references()
output fromGrandchild string = parent::child::grandchild.properties.style
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();

model.GetAllDiagnostics().Should().BeEmpty();
Expand Down Expand Up @@ -204,7 +204,7 @@ public void NestedResources_invalid_resource_references()
output fromGrandchildInvalid string = parent::child::cousin.properties.temperature
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();

model.GetAllDiagnostics().Should().HaveDiagnostics(new []{
Expand Down Expand Up @@ -239,7 +239,7 @@ public void NestedResources_child_cannot_be_referenced_outside_of_scope()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var diagnostics = compilation.GetEntrypointSemanticModel().GetAllDiagnostics();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP057", DiagnosticLevel.Error, "The name \"child\" does not exist in the current context."),
Expand All @@ -264,7 +264,7 @@ public void NestedResources_child_cannot_specify_qualified_type()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var diagnostics = compilation.GetEntrypointSemanticModel().GetAllDiagnostics();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP156", DiagnosticLevel.Error, "The resource type segment \"My.RP/parentType/childType@2020-01-01\" is invalid. Nested resources must specify a single type segment, and optionally can specify an api version using the format \"<type>@<apiVersion>\"."),
Expand All @@ -289,7 +289,7 @@ public void NestedResources_error_in_base_type()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var diagnostics = compilation.GetEntrypointSemanticModel().GetAllDiagnostics();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP029", DiagnosticLevel.Error, "The resource type is not valid. Specify a valid resource type of format \"<provider>/<types>@<apiVersion>\"."),
Expand Down Expand Up @@ -321,7 +321,7 @@ public void NestedResources_error_in_parent_type()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var diagnostics = compilation.GetEntrypointSemanticModel().GetAllDiagnostics();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP156", DiagnosticLevel.Error, "The resource type segment \"My.RP/parentType/childType@2020-01-01\" is invalid. Nested resources must specify a single type segment, and optionally can specify an api version using the format \"<type>@<apiVersion>\"."),
Expand All @@ -348,7 +348,7 @@ public void NestedResources_child_cycle_is_detected_correctly()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().HaveDiagnostics(new[] {
("BCP080", DiagnosticLevel.Error, "The expression is involved in a cycle (\"child\" -> \"parent\")."),
});
Expand Down Expand Up @@ -379,7 +379,7 @@ public void NestedResources_grandchild_cycle_results_in_binding_failure()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().HaveDiagnostics(new[] {
("BCP057", DiagnosticLevel.Error, "The name \"grandchild\" does not exist in the current context."),
});
Expand Down Expand Up @@ -408,7 +408,7 @@ public void NestedResources_ancestors_are_detected()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();
model.GetAllDiagnostics().Should().BeEmpty();

Expand Down Expand Up @@ -457,7 +457,7 @@ public void NestedResources_scopes_isolate_names()
}
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();
model.GetAllDiagnostics().Should().BeEmpty();

Expand Down Expand Up @@ -556,7 +556,7 @@ public void NestedResources_can_get_declared_type_for_property_completion()
output hmmmm string = parent::child.properties
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();

var output = model.Root.OutputDeclarations.Single();
Expand All @@ -574,7 +574,7 @@ public void NestedResources_provides_correct_error_for_resource_access_with_brok
output foo string = broken::fake
";

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program));
var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), SyntaxTreeGroupingFactory.CreateFromText(program));
var model = compilation.GetEntrypointSemanticModel();
model.GetAllDiagnostics().Should().HaveDiagnostics(new[] {
("BCP118", DiagnosticLevel.Error, "Expected the \"{\" character, the \"[\" character, or the \"if\" keyword at this location."),
Expand Down
Loading