|
| 1 | +/* |
| 2 | +Copyright 2023 Akamai Technologies, Inc. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha2 |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func TestDeleteCondition(t *testing.T) { |
| 28 | + t.Parallel() |
| 29 | + |
| 30 | + tests := []struct { |
| 31 | + name string |
| 32 | + length int |
| 33 | + delta int |
| 34 | + del string |
| 35 | + }{ |
| 36 | + {name: "empty", length: 0, del: "type0"}, |
| 37 | + {name: "delete-only", length: 1, del: "type0", delta: -1}, |
| 38 | + {name: "delete-first", length: 3, del: "type0", delta: -1}, |
| 39 | + {name: "delete-last", length: 3, del: "type2", delta: -1}, |
| 40 | + {name: "delete-missing", length: 3, del: "type3"}, |
| 41 | + } |
| 42 | + |
| 43 | + for _, tc := range tests { |
| 44 | + t.Run(tc.name, func(t *testing.T) { |
| 45 | + t.Parallel() |
| 46 | + |
| 47 | + conds := make([]metav1.Condition, tc.length) |
| 48 | + for i := 0; i < tc.length; i++ { |
| 49 | + conds[i] = metav1.Condition{Type: fmt.Sprintf("type%d", i)} |
| 50 | + } |
| 51 | + lm := &LinodeMachine{ |
| 52 | + Status: LinodeMachineStatus{ |
| 53 | + Conditions: conds, |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + lm.DeleteCondition(tc.del) |
| 58 | + assert.NotContains(t, lm.Status.Conditions, tc.del) |
| 59 | + assert.Len(t, lm.Status.Conditions, tc.length+tc.delta) |
| 60 | + }) |
| 61 | + } |
| 62 | +} |
0 commit comments