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

Any way to test contiain_file( ).with_content() with a full multi line string? #100

Open
Cinderhaze opened this issue Jan 17, 2024 · 4 comments
Labels

Comments

@Cinderhaze
Copy link

Cinderhaze commented Jan 17, 2024

Describe the Bug

When using a multi-line string, if I use it { is.expected_to contain_file('/mock/file.sh').with_content(multiline_content) } to do some initial simple 'golden master' style testing of a templated file, I get back a failed test with output that indicates a failed test, but shows no Diff. Is there a good way to check the full content of a file? I was wondering if it was related to the output problems listed in rodjek#327, about suppressing trailing newlines.

Failure/Error: it { is expected.to contain_file('/mock/file.sh').with_content(multiline_content) }
  expected that the catalogue would contain File[/mock/file.sh] with content set to supplied string
  Diff: 
    <The diff is empty, are your objects producing identical '#inspect' output?>

Expected Behavior

I would expect either a match, or a Diff that shows what is different. Ideally, I would love an example on the tutorial page of how to do a full file comparison.

Environment

  • Version: 4.0.2, installed via pdk 3.0.1
  • Platform: RHEL8
@Cinderhaze Cinderhaze added the bug label Jan 17, 2024
@ekohl
Copy link

ekohl commented Jan 17, 2024

The diff can eat line endings. Very annoying, but it should work if they match

@nabertrand
Copy link

You might try https://github.com/enterprisemodules/puppet-catalog_rspec to generate the content string. You might need pdk test unit -v to see the output or pdk bundle exec rake spec_standalone if that still hides the output.

@ekohl
Copy link

ekohl commented Jan 29, 2024

If you want to resolve this, you should provide a reproducer.

@Cinderhaze
Copy link
Author

Sorry, I didn't see your update! notifications get lost, and I am working on an air-gapped system, so a reproducer isn't so direct to pull over. I'll see if I can whip one up at home.

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

No branches or pull requests

3 participants