davidradl commented on code in PR #1068: URL: https://github.com/apache/flink-kubernetes-operator/pull/1068#discussion_r2897007766
########## flink-kubernetes-operator-api/src/test/java/org/apache/flink/kubernetes/operator/api/utils/ConditionsUtilsTest.java: ########## @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.kubernetes.operator.api.utils; + +import io.fabric8.kubernetes.api.model.Condition; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.time.Instant; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +/** Test for {@link ConditionsUtils}. */ +public class ConditionsUtilsTest { + + private static Stream<Arguments> updateLastTransitionTimeParams() { + String existingConditionLastTransitionTime = Instant.now().toString(); + + return Stream.of( + // Test Null + Arguments.of(Collections.emptyList(), null, null, true), + + // Test Empty Conditions + Arguments.of( + Collections.emptyList(), + new Condition( + "lastTransitionTime", "message", 0L, "reason", "status", "type"), + new Condition( + "lastTransitionTime", "message", 0L, "reason", "status", "type"), + false), + + // Test Correct Update + Arguments.of( + List.of( + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type")), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type"), + new Condition( + "lastTransitionTime", "message", 0L, "reason", "status", "type"), + true), + + // Test Status Unchanged + Arguments.of( + List.of( + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type")), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type"), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type"), + true), + + // Test Status Changed + Arguments.of( + List.of( + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status1", + "type")), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status2", + "type"), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status2", + "type"), + false), + + // Test Multiple Conditions with Multiple Types + Arguments.of( + List.of( + new Condition("time1", "message", 0L, "reason", "status", "type1"), + new Condition("time2", "message", 0L, "reason", "status", "type1"), + new Condition("time3", "message", 0L, "reason", "status", "type2")), + new Condition("time1", "message", 0L, "reason", "status", "type1"), + new Condition( + "lastTransitionTime", "message", 0L, "reason", "status", "type1"), + true), + + // Test No Matching Type + Arguments.of( + List.of( + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type1")), + new Condition( + existingConditionLastTransitionTime, + "message", + 0L, + "reason", + "status", + "type2"), + new Condition( + "lastTransitionTime", "message", 0L, "reason", "status", "type2"), + false)); + } + + @ParameterizedTest + @MethodSource("updateLastTransitionTimeParams") + void testUpdateLastTransitionTime( + List<Condition> conditions, Condition expected, Condition actual, boolean equals) { + ConditionsUtils.updateLastTransitionTime(conditions, actual); + if (equals) { + assertEquals(expected, actual); + } else { + assertNotEquals(expected, actual); Review Comment: Looking at this again. With the current code there will be only ever one condition - which is running - but it will have different reasons. We should remove the multi condition tests and just drive the code paths in that method. I suspect the current testing is overkill (sorry I did not notice before) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
