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

Allow empty maps for yaml (#907) #908

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stores/yaml/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ func TestEmpty2(t *testing.T) {
}
*/

func TestEmpty3(t *testing.T) {
branches, err := (&Store{}).LoadPlainFile([]byte("{}\n"))
assert.Nil(t, err)
assert.Equal(t, len(branches), 1)
bytes, err := (&Store{}).EmitPlainFile(branches)
assert.Nil(t, err)
assert.Equal(t, "{}\n", string(bytes))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fails like this:

--- FAIL: TestEmpty3 (0.00s)
    store_test.go:206: 
                Error Trace:    store_test.go:206
                Error:          Expected nil, but got: &errors.errorString{s:"Error marshaling to yaml: yaml: expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, but got document end"}
                Test:           TestEmpty3
    store_test.go:207: 
                Error Trace:    store_test.go:207
                Error:          Not equal: 
                                expected: "{}\n"
                                actual  : ""
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1,2 +1 @@
                                -{}
                                 
                Test:           TestEmpty3
FAIL
coverage: 69.5% of statements
FAIL    go.mozilla.org/sops/v3/stores/yaml      0.066s
FAIL

I wanted to demonstrate that in CI, but the test failed fast for #882.

func TestComment6(t *testing.T) {
branches, err := (&Store{}).LoadPlainFile(COMMENT_6)
assert.Nil(t, err)
Expand Down