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
Add support W3C Extended Log File Format in Import-Csv #2482
Conversation
Hi @iSazonov, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
@adityapatwardhan and @JamesWTruher Please review |
1115a94
to
d6f25ce
Compare
} | ||
It "Should be able to call without error" { | ||
{ Import-Csv $testCsv @HeaderParams } | Should Not Throw | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test can be removed, if the next test throws we get this test anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
|
||
$actual | Should Not BeNullOrEmpty | ||
$actual.GetType().BaseType | Should Be array | ||
$actual.count | Should Be 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be useful to actually verify an imported value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test ("Should be able to import rights values") that checks the imported values is below the test.
I think this checks of return type and count of records should be.
$actualAlias[0].'Column1' | Should Be $actualCmdlet[0].'Column1' | ||
$actualAlias[0].'Column2' | Should Be $actualCmdlet[0].'Column2' | ||
$actualAlias[0].'Column 3' | Should Be $actualCmdlet[0].'Column 3' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah - remove this test - just validate that the alias is present and is set correctly. There is no real need to actually invoke the alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both alias test are removed.
|
||
AfterAll { | ||
Remove-Item -Path $testfile -Force | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since $TESTDRIVE is cleaned up automatically by Pester, this shouldn't be needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
I'm a little worried about backward compatibility here - I didn't see any discussion about that. |
@JamesWTruher Thanks for review! $temp = import-csv -path $testfile -header $customheader
# Skip first lines starting with '#'
$result = $temp | Select -Skip 5 I personally never use this technique. Certainly there are many personal scripts that parse logs and that can be broken. But I think that their authors will be happy to see that now they can read this format logs directly without workarrounds. |
Now I analyzed the powershell scripts on GitHub as @daxian-dbw (AnalyzeSelectObject.ps1) |
data2,2,B | ||
data3,3,C | ||
data4,4,D | ||
Column1,Column2,Column 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see another test case similar to this one that contains a comment as the first line. It can be as simple as "# Comment". This case is covered by the existing Import-Csv cmdlet and it'd be nice to prove it still works as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
# The file does not have header | ||
# (w/o Delimiter here we get throw (bug?)) | ||
$HeaderParams = @{Header = $orginalHeader; Delimiter = ","} | ||
$CustomHeaderParams = @{Header = $customHeader; Delimiter = ","} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is duplicated and it is safe to move to line 41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
|
||
It "Should be able to assign to a variable" { | ||
$actual = Import-Csv -Path $testCsv @HeaderParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is redundant because all the other tests verify the same condition as well. If Import-Csv cannot assign the result to a variable, you won't be able to validate that it imported the correct headers and values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the essence of the test is $actual.count | Should Be 4
No other test does not check this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$actual.count | Should Be 4
would fit nicely on line 75. Then this test won't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
$actualfields | Should Be $customHeader | ||
} | ||
|
||
It "Should be able to import rights values" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"right" or "correct"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,4 @@ | |||
data1,1,A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Descriptive file names would be nice to have here. Something like:
TestImportCsv1 --> TestImportCsv_NoHeader
TestImportCsv2 --> TestImportCsv_WithHeader
TestImportCsv3 --> TestImportCsv_W3C_ELF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
1. Add support W3C Extended Log File Format 2. Refactoring Import-Csv tests 3. Add #Type tests
@iSazonov The change and tests look good based on my limited experience with the cmdlet. My only concern is the discussion earlier in the thread regarding this change's potential to be a "breaking change" of the existing behavior. |
@mirichmo Thanks for review! I know only one breaking scenario. I described it above. This is exactly that I was looking for in scripts on GitHub for analysis. I have found no scripts with the breaking scenario. Maybe we should ask Powershell team for help and then Powershell committee to make conclusion? |
@SteveL-MSFT Should this be evaluated by the committee? |
@mirichmo Thanks for the review! |
@mirichmo since this is a breaking change, @PowerShell/powershell-committee will review this |
@SteveL-MSFT I found another breaking scenario with custom file: #, Field2, Field3
#1, Data11, Data12
#2, Data21, Data22 Workarround: explicitly use |
Close #2480