mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
var schema = []byte(`
|
|
{
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
"title": "SAP Cloud SDK pipeline_config JSON schema",
|
|
"type": "object",
|
|
"properties": {
|
|
"general": {
|
|
"type": [
|
|
"object",
|
|
"null"
|
|
],
|
|
"properties": {
|
|
"productiveBranch": {
|
|
"type": "string",
|
|
"default": "master"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`)
|
|
|
|
var patch = []byte(`
|
|
[
|
|
{
|
|
"op": "add",
|
|
"path": "/properties/general/properties/gitCredentialsId",
|
|
"value": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
]
|
|
`)
|
|
|
|
var patchedSchema = []byte(`{
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
"title": "SAP Cloud SDK pipeline_config JSON schema",
|
|
"type": "object",
|
|
"properties": {
|
|
"general": {
|
|
"type": [
|
|
"object",
|
|
"null"
|
|
],
|
|
"properties": {
|
|
"productiveBranch": {
|
|
"type": "string",
|
|
"default": "master"
|
|
},
|
|
"gitCredentialsId": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`)
|
|
|
|
func TestSchemaPatch(t *testing.T) {
|
|
t.Run("default", func(t *testing.T) {
|
|
options := jsonApplyPatchOptions{
|
|
Input: "schema.json",
|
|
Patch: "patch.json",
|
|
Output: "output.json",
|
|
}
|
|
filesMock := mock.FilesMock{}
|
|
filesMock.AddFile("schema.json", schema)
|
|
filesMock.AddFile("patch.json", patch)
|
|
err := runJsonApplyPatch(&options, &filesMock)
|
|
assert.NoError(t, err)
|
|
patchedSchemaResult, err := filesMock.FileRead("output.json")
|
|
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)
|
|
})
|
|
}
|