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

cqthyy/params integration unit tests #7352

Merged
merged 17 commits into from
Jun 30, 2022

Conversation

cqthyy
Copy link
Contributor

@cqthyy cqthyy commented Jun 24, 2022

Bicep parameter file parser integration tests & baseline generation implemented, syntax visitor methods implemented

Microsoft Reviewers: Open in CodeFlow

[TestClass]
public class ParamsParserTests
{
private class SyntaxCollectorVisitor : SyntaxVisitor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the syntax collector visitor in PaserTests. It might be worth extracting it to a new file and make it public helper class.

var syntaxList = SyntaxCollectorVisitor.Build(program);
var syntaxByParent = syntaxList.ToLookup(x => x.Parent);

string getLoggingString(SyntaxCollectorVisitor.SyntaxItem data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also make it a public helper method of SyntaxCollectorVisitor which both ParserTests and ParamsParserTests can reuse.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, would be good to extract common logic here

'h'
]
}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the we allow non-literal values at syntax level, we can add some test cases to ensure they can also be parsed, for example:

param myFunction = union({}, {})

param myComplexArrWithFunction = [
  {
    foo: resourceGroup()
  }
  true
  [
    42
  ]
]

They can also be useful for validating semantic diagnostics later, since we are going to implement semantic checking to block non-literal values.

Comment on lines 63 to 66
if (dataSet.BicepParam is null)
{
return;
}
Copy link
Member

@anthony-c-martin anthony-c-martin Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than skipping over tests you want to ignore with a return (which will result in these tests being reported as "success"), it would be better to change the GetData method below to something like GetParamsData and do the filtering there.

Copy link
Contributor

@shenglol shenglol Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to comment this. GetData already does the filtering, but it makes sense to change the name to GetParamsData. Also, I think it's better to throw new InvalidOperationException($"Expected {dataSet.BicepParam} to be non-null"); here in case DataSets.ParamDataSets returns null BicepParam.

@Usman0111 Usman0111 closed this Jun 28, 2022
@Usman0111 Usman0111 reopened this Jun 28, 2022
@cqthyy cqthyy closed this Jun 28, 2022
@cqthyy cqthyy reopened this Jun 28, 2022
Copy link
Member

@majastrz majastrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@@ -0,0 +1,68 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git by default will convert line endings depending on whether you're checking out code on Windows (\r\n) or Unix/Linux (\n). This causes problems for the baseline tests - to fix this, you may need to copy the config we added for .bicep to your new extension - to respect the newline format of the file and avoid converting on different platforms:

bicep/.gitattributes

Lines 1 to 2 in 6d0eeaf

*.bicep -text
*.ts text eol=lf

@cqthyy cqthyy merged commit e9fdf07 into Bicep-params-file Jun 30, 2022
@cqthyy cqthyy deleted the cqthyy/params-integration-unit-tests branch June 30, 2022 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

integration tests & unit test revisions for Bicep parameter file parser
5 participants