From fa545b142df346ddf8a98ee8fbb7e0a886ad4ab4 Mon Sep 17 00:00:00 2001 From: Sebastien Duthil Date: Sun, 31 Mar 2024 17:18:05 +0200 Subject: [PATCH] outputs: add trailing \n at the end of json files Signed-off-by: Sebastien Duthil --- functional-tests/src/lib.rs | 3 ++- stores/json/store.go | 2 ++ stores/json/store_test.go | 15 ++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/functional-tests/src/lib.rs b/functional-tests/src/lib.rs index 2ec7a891b..5a2d5e593 100644 --- a/functional-tests/src/lib.rs +++ b/functional-tests/src/lib.rs @@ -1168,7 +1168,8 @@ bar: |- r#"{ "foo": "bar", "bar": "baz\nbam" -}"# +} +"# ); } diff --git a/stores/json/store.go b/stores/json/store.go index e9df1b554..e1ef22046 100644 --- a/stores/json/store.go +++ b/stores/json/store.go @@ -326,6 +326,7 @@ func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) { if err != nil { return nil, fmt.Errorf("Error marshaling to json: %s", err) } + out = append(out, '\n') return out, nil } @@ -336,6 +337,7 @@ func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) { if err != nil { return nil, fmt.Errorf("Error marshaling to json: %s", err) } + out = append(out, '\n') return out, nil } diff --git a/stores/json/store_test.go b/stores/json/store_test.go index eca6d3e96..9a09a63fa 100644 --- a/stores/json/store_test.go +++ b/stores/json/store_test.go @@ -34,7 +34,8 @@ func TestDecodeJSON(t *testing.T) { } } } -}` +} +` expected := sops.TreeBranch{ sops.TreeItem{ Key: "glossary", @@ -312,7 +313,8 @@ func TestEncodeJSONArrayOfObjects(t *testing.T) { }, 2 ] -}` +} +` store := Store{ config: config.JSONStoreConfig{ Indent: -1, @@ -446,7 +448,8 @@ func TestIndentTwoSpaces(t *testing.T) { }, 2 ] -}` +} +` store := Store{ config: config.JSONStoreConfig{ Indent: 2, @@ -488,7 +491,8 @@ func TestIndentDefault(t *testing.T) { }, 2 ] -}` +} +` store := Store{ config: config.JSONStoreConfig{ Indent: -1, @@ -530,7 +534,8 @@ func TestNoIndent(t *testing.T) { }, 2 ] -}` +} +` store := Store{ config: config.JSONStoreConfig{ Indent: 0,