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

The example in the documentation for TestDrive:\ no longer work #1733

Closed
nohwnd opened this issue Oct 24, 2020 · 7 comments · Fixed by #1894 or pester/docs#102
Closed

The example in the documentation for TestDrive:\ no longer work #1733

nohwnd opened this issue Oct 24, 2020 · 7 comments · Fixed by #1894 or pester/docs#102
Milestone

Comments

@nohwnd
Copy link
Member

nohwnd commented Oct 24, 2020

The example in the documentation for TestDrive:\ also no longer works. It needs to be rewritten to use a BeforeAll block.

Originally posted by @markwragg in #1645 (comment)

@nohwnd nohwnd added this to the 5.2 milestone Oct 24, 2020
@dgroh
Copy link

dgroh commented Mar 18, 2021

It would also great to add in the docs that Set-Content is needed in order to create the file otherwise it shows that file does not exist as well. How should we handle other file types like zip files for example?

@nohwnd
Copy link
Member Author

nohwnd commented Mar 18, 2021

TestDrive is no different than any other location on disk. In fact it is just an "alias" of %temp%/<some random path>, that will be cleaned up after your test finishes to make working with files more convenient to you. You would handle a zip file in the same way you'd handle it if it was on any other file path.

@nohwnd
Copy link
Member Author

nohwnd commented Mar 18, 2021

Or maybe I am misunderstanding what you tried to say.

@dgroh
Copy link

dgroh commented Mar 18, 2021

I understand how TestDrive work and I use it already mostly for json and text files. I had a case where I have a zip and for zip files IMO it doesn't make sense to use Set-Content. Here is my approach:

    $mockFile = "TestDrive:\File.zip"
    Set-Content $mockFile -Value "any content"

Maybe this is the way, but it just does not feel right!

@nohwnd
Copy link
Member Author

nohwnd commented Mar 18, 2021

I am still not sure what you are after. The documentation does not tell you to write zip files using Set-Content. It might be fine if you are just checking a presence of a zip file, but won't work if you try to unzip it. The documentation just shows one example of how to create a file on TestDrive, it does not force you to use Set-Content.

@dgroh
Copy link

dgroh commented Mar 18, 2021

Ok, I might be doing something wrong then, because without Set-Content I get an exception that the file does not exist.
And I don't expect to unzip the file, I just want to make the file available.

@nohwnd
Copy link
Member Author

nohwnd commented Mar 18, 2021

You are not doing anything wrong. 🙂 TestDrive points into an empty folder. This folder will be deleted once your top level Describe ends.

If you don't put any files in TestDrive the won't be any.

TestDrive is a way to give you a place on your disk:

  • that is unique to each test suite, to avoid cross pollution between different test suites, while keeping sharing data between tests in a single suite reasonably simple.
  • that you don't have to clean up. To avoid leaving your temporary files in your temp folder, or somewhere else on disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants