-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1476 from target/sched-data-preserve-fields
temp schedules: preserve unknown fields
- Loading branch information
Showing
7 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package jsonutil | ||
|
||
import "encoding/json" | ||
|
||
// Apply can be used in place of `json.Marshal` but with the effect of | ||
// merging into the original document. | ||
func Apply(original []byte, src interface{}) ([]byte, error) { | ||
srcDoc, err := json.Marshal(src) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return Merge(original, srcDoc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jsonutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestApply(t *testing.T) { | ||
const rawDoc = `{"Bin": "baz","Foo": "bar"}` | ||
var newDoc struct { | ||
Foo string | ||
} | ||
newDoc.Foo = "FOO" | ||
|
||
data, err := Apply([]byte(rawDoc), newDoc) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `{"Bin":"baz","Foo":"FOO"}`, string(data)) | ||
|
||
data, err = Apply(nil, newDoc) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `{"Foo":"FOO"}`, string(data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters