forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParameterFileTests.cs
99 lines (88 loc) · 3.16 KB
/
ParameterFileTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.Core.Diagnostics;
using Bicep.Core.UnitTests.Assertions;
using Bicep.Core.UnitTests.Utils;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Bicep.Core.IntegrationTests
{
[TestClass]
public class ParameterFileTests
{
[TestMethod]
public void Parameters_file_cannot_reference_non_bicep_files()
{
var result = CompilationHelper.CompileParams(
("parameters.bicepparam", @"
using './foo.bicepparam'
"),
("foo.bicepparam", ""));
result.Should().OnlyContainDiagnostic("BCP276", DiagnosticLevel.Error, "A using declaration can only reference a Bicep file.");
}
[TestMethod]
public void Parameters_file_cannot_self_reference()
{
var result = CompilationHelper.CompileParams(("parameters.bicepparam", @"
using './parameters.bicepparam'
"));
result.Should().OnlyContainDiagnostic("BCP278", DiagnosticLevel.Error, "This parameters file references itself, which is not allowed.");
}
[TestMethod]
public void Parameters_file_cycles_should_be_detected()
{
var result = CompilationHelper.CompileParams(
("parameters.bicepparam", @"
using './one.bicepparam'
"),
("one.bicepparam", @"
using './two.bicepparam'
"),
("two.bicepparam", @"
using './one.bicepparam'
"));
result.Diagnostics.Should().SatisfyRespectively(
x =>
{
x.Code.Should().Be("BCP095");
x.Level.Should().Be(DiagnosticLevel.Error);
x.Message.Should().StartWith("The file is involved in a cycle (\"");
x.Message.Should().EndWith("\").");
x.Message.Should().ContainAll("one.bicepparam\" -> \"", "two.bicepparam\").");
});
}
[TestMethod]
public void Params_file_with_not_using_declaration_should_log_diagnostic()
{
var result = CompilationHelper.CompileParams(
("parameters.bicepparam", @"
param foo = 'bar'
"),
("main.bicep", @"
param foo string
"));
using(new AssertionScope())
{
result.Parameters.Should().BeNull();
result.Diagnostics.Should().HaveDiagnostics(new[]
{
("BCP261", DiagnosticLevel.Error, "A using declaration must be present in this parameters file.")
});
}
}
[TestMethod]
public void Parameters_file_cannot_reference_non_existing_env_variable()
{
var result = CompilationHelper.CompileParams(
("parameters.bicepparam", @"
using 'foo.bicep'
param fromEnv=readEnvironmentVariable('stringEnvVariable')
"),
("foo.bicep", @"param fromEnv string"));
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new []{
("BCP338", DiagnosticLevel.Error,
"Failed to evaluate parameter \"stringEnvVariable\": Environment variable does not exist, and no default value set")});
}
}
}