1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-11 13:53:53 +02:00

Let json patcher fail if file not found (#1694)

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
This commit is contained in:
Daniel Kurzynski 2020-06-19 20:13:20 +02:00 committed by GitHub
parent 0d1b94adb3
commit 8f9ed0766c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -19,12 +19,12 @@ func jsonApplyPatch(config jsonApplyPatchOptions, telemetryData *telemetry.Custo
func runJsonApplyPatch(config *jsonApplyPatchOptions, fileUtils piperutils.FileUtils) error {
schema, err := fileUtils.FileRead(config.Input)
if err != nil {
return nil
return err
}
patchFile, err := fileUtils.FileRead(config.Patch)
if err != nil {
return nil
return err
}
patcher, err := jsonpatch.DecodePatch(patchFile)
if err != nil {

View File

@ -79,4 +79,15 @@ func TestSchemaPatch(t *testing.T) {
assert.NoError(t, err)
assert.JSONEq(t, string(patchedSchema), string(patchedSchemaResult))
})
t.Run("file does not exist", func(t *testing.T) {
options := jsonApplyPatchOptions{
Input: "schema.json",
Patch: "patch.json",
Output: "output.json",
}
filesMock := mock.FilesMock{}
err := runJsonApplyPatch(&options, &filesMock)
assert.Error(t, err)
})
}