Skip to content

Conversation

@malmond77
Copy link
Contributor

Two parts:

  1. Demonstrate the bug in a unit test
  2. Fix the bug

This commit demonstrates a bug in state handling. Every modification involves a read, modify, write. This unit test mocks out just enough to show that a state file with ssl -> true is read correctly, changed, then produces an invalid json file with two entries in the hash with the same key. This is the key issue as reported in facebook#115.

```
[malmond@devvm1846.vll1 ~/local/taste-tester]
/opt/chefdk/embedded/bin/rspec .
F

Failures:

  1) TasteTester::State should serialize changes correctly
     Failure/Error: expect(@buffer.string).to eq('{"ssl":false}')

       expected: "{\"ssl\":false}"
            got: "{\"ssl\":true,\"ssl\":false}"

       (compared using ==)
     # ./spec/taste-tester_spec.rb:20:in `block (2 levels) in <top
     # (required)>'

Finished in 0.01544 seconds (files took 0.27334 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/taste-tester_spec.rb:6 # TasteTester::State should serialize changes correctly
```

Signed-off-by: Matthew Almond <malmond@fb.com>
This is to fix the issue reported in facebook#115.

It is possible to modify `state.rb` to use Mash in a way that does merge keys properly. However this is more complex than neccessary. The existing code already uses `.to_s` on reads. Given a choice between the two approaches, I am chosing to keep the code simpler and remove the unneccessary import.

Signed-off-by: Matthew Almond <malmond@fb.com>
Copy link
Collaborator

@jaymzh jaymzh left a comment

Choose a reason for hiding this comment

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

JSON forces all keys to strings.
Mash forces all keys to be consistent.

The existing code fixes the bug I opened.... and I don't see this showing any legitimate bug, it's just doing the same work manually.

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.

4 participants