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

Add support W3C Extended Log File Format in Import-Csv #2482

Merged
merged 4 commits into from Nov 18, 2016

Conversation

iSazonov
Copy link
Collaborator

  1. Add support W3C Extended Log File Format
  2. Add tests and new csv file for tests

Close #2480

@msftclas
Copy link

Hi @iSazonov, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

@mirichmo
Copy link
Member

@adityapatwardhan and @JamesWTruher Please review

}
It "Should be able to call without error" {
{ Import-Csv $testCsv @HeaderParams } | Should Not Throw
}
Copy link
Member

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

Copy link
Collaborator Author

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
Copy link
Member

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?

Copy link
Collaborator Author

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'
}
Copy link
Member

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

Copy link
Collaborator Author

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
}
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

@JamesWTruher
Copy link
Member

I'm a little worried about backward compatibility here - I didn't see any discussion about that.

@JamesWTruher JamesWTruher self-assigned this Oct 17, 2016
@iSazonov
Copy link
Collaborator Author

@JamesWTruher Thanks for review!
And I only see one breaking scenario when using "dirty" trick:

$temp = import-csv -path $testfile -header $customheader
# Skip first lines starting with '#'
$result = $temp | Select -Skip 5

I personally never use this technique.
I cannot analyze the powershell scripts on GitHub as @daxian-dbw AnalyzeSelectObject.ps1

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.

@iSazonov
Copy link
Collaborator Author

Now I analyzed the powershell scripts on GitHub as @daxian-dbw (AnalyzeSelectObject.ps1)
From 1106 files I could find only one (ComputerManagement.psm1) that uses the above method but definitely not for a W3C log format.

data2,2,B
data3,3,C
data4,4,D
Column1,Column2,Column 3
Copy link
Member

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.

Copy link
Collaborator Author

@iSazonov iSazonov Nov 8, 2016

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 = ","}
Copy link
Member

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

Copy link
Collaborator Author

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
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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" {
Copy link
Member

Choose a reason for hiding this comment

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

"right" or "correct"

Copy link
Collaborator Author

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
Copy link
Member

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

Copy link
Collaborator Author

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
@mirichmo
Copy link
Member

@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.
Can you please be more specific regarding the scenarios you investigated and their results?

@iSazonov
Copy link
Collaborator Author

@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.
So the question is whether there are other breaking scenarios?

Maybe we should ask Powershell team for help and then Powershell committee to make conclusion?

@mirichmo
Copy link
Member

@SteveL-MSFT Should this be evaluated by the committee?

@mirichmo mirichmo merged commit 469924d into PowerShell:master Nov 18, 2016
@iSazonov
Copy link
Collaborator Author

@mirichmo Thanks for the review!

@iSazonov iSazonov deleted the importcsv branch November 18, 2016 05:13
@SteveL-MSFT SteveL-MSFT added Review - Committee The PR/Issue needs a review from the PowerShell Committee Breaking-Change breaking change that may affect users labels Nov 18, 2016
@SteveL-MSFT
Copy link
Member

@mirichmo since this is a breaking change, @PowerShell/powershell-committee will review this

@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT I found another breaking scenario with custom file:

#, Field2, Field3
#1, Data11, Data12
#2, Data21, Data22

Workarround: explicitly use Header

@SteveL-MSFT SteveL-MSFT removed the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Feb 2, 2017
@iSazonov iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Jun 17, 2017
@joeyaiello joeyaiello removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking-Change breaking change that may affect users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants