Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emergency] correct array index in backtrace #16

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func backtrace(s, t []interface{}, p string, i int, j int, matrix [][]int) []Ope
return append([]Operation{op}, backtrace(s, t, p, i-1, j-1, matrix)...)
}

p2, _ := handleValues(s[j-1], t[j-1], makePath(p, i-1), []Operation{})
p2, _ := handleValues(s[i-1], t[j-1], makePath(p, i-1), []Operation{})
return append(p2, backtrace(s, t, p, i-1, j-1, matrix)...)
}
if i > 0 && j > 0 && matrix[i-1][j-1] == matrix[i][j] {
Expand Down
66 changes: 66 additions & 0 deletions jsonpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,70 @@ var (
}`
)

var (
oldArray = `{
"apiVersion": "kubedb.com/v1alpha1",
"kind": "Elasticsearch",
"metadata": {
"name": "quick-elasticsearch",
"namespace": "demo"
},
"spec": {
"tolerations": [
{
"key": "node.kubernetes.io/key1",
"operator": "Equal",
"value": "value1",
"effect": "NoSchedule"
},
{
"key": "node.kubernetes.io/key2",
"operator": "Equal",
"value": "value2",
"effect": "NoSchedule"
},
{
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
},
{
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
}
]
}
}`

newArray = `{
"apiVersion": "kubedb.com/v1alpha1",
"kind": "Elasticsearch",
"metadata": {
"name": "quick-elasticsearch",
"namespace": "demo"
},
"spec": {
"tolerations": [
{
"key": "node.kubernetes.io/key2",
"operator": "Equal",
"value": "value2",
"effect": "NoSchedule"
},
{
"key": "node.kubernetes.io/key1",
"operator": "Equal",
"value": "value1",
"effect": "NoSchedule"
}
]
}
}`
)

func TestCreatePatch(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -777,6 +841,8 @@ func TestCreatePatch(t *testing.T) {
{"Kubernetes:Annotations", oldDeployment, newDeployment},
// crd with nested object
{"Nested Member Object", oldNestedObj, newNestedObj},
// array with different order
{"Different Array", oldArray, newArray},
{"Array at root", `[{"asdf":"qwerty"}]`, `[{"asdf":"bla"},{"asdf":"zzz"}]`},
{"Empty array at root", `[]`, `[{"asdf":"bla"},{"asdf":"zzz"}]`},
}
Expand Down