Skip to content

Commit

Permalink
Merge pull request openshift#199 from wking/setInt32Ptr-both-nil
Browse files Browse the repository at this point in the history
lib/resourcemerge/core: Fix setInt32Ptr for "both nil" case
  • Loading branch information
openshift-merge-robot authored Jun 7, 2019
2 parents 40ba3b6 + eace91c commit 5f087d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/resourcemerge/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ func setInt32(modified *bool, existing *int32, required int32) {
}

func setInt32Ptr(modified *bool, existing **int32, required *int32) {
if *existing == nil && required == nil {
return
}
if *existing == nil || (required == nil && *existing != nil) {
*modified = true
*existing = required
Expand Down
41 changes: 41 additions & 0 deletions lib/resourcemerge/core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package resourcemerge

import (
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/utils/pointer"
)

func TestEnsurePodSpec(t *testing.T) {
tests := []struct {
name string
existing corev1.PodSpec
input corev1.PodSpec

expectedModified bool
expected corev1.PodSpec
}{{
name: "empty inputs",
existing: corev1.PodSpec{},
input: corev1.PodSpec{},

expectedModified: false,
expected: corev1.PodSpec{},
}}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
modified := pointer.BoolPtr(false)
ensurePodSpec(modified, &test.existing, test.input)
if *modified != test.expectedModified {
t.Errorf("mismatch modified got: %v want: %v", *modified, test.expectedModified)
}

if !equality.Semantic.DeepEqual(test.existing, test.expected) {
t.Errorf("mismatch PodSpec got: %v want: %v", test.existing, test.expected)
}
})
}
}

0 comments on commit 5f087d4

Please sign in to comment.