k8s.io/kubernetes@v1.29.3/pkg/kubelet/container/sync_result_test.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 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 container 18 19 import ( 20 "errors" 21 "testing" 22 ) 23 24 func TestPodSyncResult(t *testing.T) { 25 okResults := []*SyncResult{ 26 NewSyncResult(StartContainer, "container_0"), 27 NewSyncResult(SetupNetwork, "pod"), 28 } 29 errResults := []*SyncResult{ 30 NewSyncResult(KillContainer, "container_1"), 31 NewSyncResult(TeardownNetwork, "pod"), 32 } 33 errResults[0].Fail(errors.New("error_0"), "message_0") 34 errResults[1].Fail(errors.New("error_1"), "message_1") 35 36 // If the PodSyncResult doesn't contain error result, it should not be error 37 result := PodSyncResult{} 38 result.AddSyncResult(okResults...) 39 if result.Error() != nil { 40 t.Errorf("PodSyncResult should not be error: %v", result) 41 } 42 43 // If the PodSyncResult contains error result, it should be error 44 result = PodSyncResult{} 45 result.AddSyncResult(okResults...) 46 result.AddSyncResult(errResults...) 47 if result.Error() == nil { 48 t.Errorf("PodSyncResult should be error: %v", result) 49 } 50 51 // If the PodSyncResult is failed, it should be error 52 result = PodSyncResult{} 53 result.AddSyncResult(okResults...) 54 result.Fail(errors.New("error")) 55 if result.Error() == nil { 56 t.Errorf("PodSyncResult should be error: %v", result) 57 } 58 59 // If the PodSyncResult is added an error PodSyncResult, it should be error 60 errResult := PodSyncResult{} 61 errResult.AddSyncResult(errResults...) 62 result = PodSyncResult{} 63 result.AddSyncResult(okResults...) 64 result.AddPodSyncResult(errResult) 65 if result.Error() == nil { 66 t.Errorf("PodSyncResult should be error: %v", result) 67 } 68 }