1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Allow no indent at all for json store

Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
This commit is contained in:
Bastien Wermeille
2023-09-14 20:41:56 +02:00
parent c6dc5267e5
commit 755c16d49c
5 changed files with 64 additions and 7 deletions

View File

@@ -250,7 +250,7 @@ func (store Store) treeBranchFromJSON(in []byte) (sops.TreeBranch, error) {
func (store Store) reindentJSON(in []byte) ([]byte, error) {
var out bytes.Buffer
indent := "\t"
if store.config.Indent != 0 {
if store.config.Indent != -1 {
indent = strings.Repeat(" ", store.config.Indent)
}
err := json.Indent(&out, in, "", indent)

View File

@@ -313,7 +313,11 @@ func TestEncodeJSONArrayOfObjects(t *testing.T) {
2
]
}`
store := Store{}
store := Store{
config: config.JSONStoreConfig{
Indent: -1,
},
}
out, err := store.EmitPlainFile(tree.Branches)
assert.Nil(t, err)
assert.Equal(t, expected, string(out))
@@ -485,7 +489,53 @@ func TestIndentDefault(t *testing.T) {
2
]
}`
store := Store{}
store := Store{
config: config.JSONStoreConfig{
Indent: -1,
},
}
out, err := store.EmitPlainFile(tree.Branches)
assert.Nil(t, err)
assert.Equal(t, expected, string(out))
}
func TestNoIndent(t *testing.T) {
tree := sops.Tree{
Branches: sops.TreeBranches{
sops.TreeBranch{
sops.TreeItem{
Key: "foo",
Value: []interface{}{
sops.TreeBranch{
sops.TreeItem{
Key: "foo",
Value: 3,
},
sops.TreeItem{
Key: "bar",
Value: false,
},
},
2,
},
},
},
},
}
expected := `{
"foo": [
{
"foo": 3,
"bar": false
},
2
]
}`
store := Store{
config: config.JSONStoreConfig{
Indent: 0,
},
}
out, err := store.EmitPlainFile(tree.Branches)
assert.Nil(t, err)
assert.Equal(t, expected, string(out))