Skip to content

Commit

Permalink
Merge pull request #11380 from sbueringer/pr-patch-test-panic
Browse files Browse the repository at this point in the history
🐛 Fix panics in patch unit tests
  • Loading branch information
k8s-ci-robot authored Nov 5, 2024
2 parents 8fe14d4 + 54bd7c8 commit 0f2dddc
Showing 1 changed file with 112 additions and 1 deletion.
113 changes: 112 additions & 1 deletion util/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,19 @@ func TestPatchHelper(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -329,13 +335,19 @@ func TestPatchHelper(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -1135,13 +1147,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -1199,13 +1217,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -1539,28 +1563,37 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "Test")
testConditionAfter := conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

testV1Beta2ConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testV1Beta2ConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testV1Beta2ConditionCopy == nil || testV1Beta2ConditionAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*testV1Beta2ConditionCopy).Match(*testV1Beta2ConditionAfter)
if err != nil || !ok {
return false
}

readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
if err != nil {
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
Expand Down Expand Up @@ -1623,27 +1656,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "Test")
testConditionAfter := conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

testV1Beta2ConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testV1Beta2ConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testV1Beta2ConditionCopy == nil || testV1Beta2ConditionAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*testV1Beta2ConditionCopy).Match(*testV1Beta2ConditionAfter)
if err != nil || !ok {
return false
}

readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -1796,13 +1841,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -1860,13 +1911,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2046,27 +2103,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testBackCompatibilityCopy := conditions.Get(objCopy, "Test")
testBackCompatibilityAfter := conditions.Get(objAfter, "Test")
if testBackCompatibilityCopy == nil || testBackCompatibilityAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testBackCompatibilityCopy).Match(*testBackCompatibilityAfter)
if err != nil || !ok {
return false
}

readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
if err != nil || !ok {
return false
}

testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2127,27 +2196,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testBackCompatibilityCopy := conditions.Get(objCopy, "Test")
testBackCompatibilityAfter := conditions.Get(objAfter, "Test")
if testBackCompatibilityCopy == nil || testBackCompatibilityAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*testBackCompatibilityCopy).Match(*testBackCompatibilityAfter)
if err != nil || !ok {
return false
}

readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
return false
}
ok, err = conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
if err != nil || !ok {
return false
}

testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2300,13 +2381,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2364,13 +2451,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
return false
}
ok, err := conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2532,13 +2625,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2597,13 +2696,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
if testConditionCopy == nil || testConditionAfter == nil {
return false
}
ok, err := v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2707,6 +2812,9 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err := v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down Expand Up @@ -2762,6 +2870,9 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {

readyBefore := v1beta2conditions.Get(obj, "Ready")
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
if readyBefore == nil || readyAfter == nil {
return false
}
ok, err := v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
Expand Down

0 comments on commit 0f2dddc

Please sign in to comment.