github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/event/v2/task_test.go (about) 1 /* 2 Copyright 2021 The Skaffold 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 v2 18 19 import ( 20 "errors" 21 "testing" 22 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" 24 proto "github.com/GoogleContainerTools/skaffold/proto/v2" 25 ) 26 27 func TestTaskFailed(t *testing.T) { 28 tcs := []struct { 29 description string 30 state *proto.State 31 phase constants.Phase 32 waitFn func() bool 33 }{ 34 { 35 description: "build failed", 36 phase: constants.Build, 37 waitFn: func() bool { 38 handler.logLock.Lock() 39 logEntry := handler.eventLog[len(handler.eventLog)-1] 40 handler.logLock.Unlock() 41 te := logEntry.GetTaskEvent() 42 return te != nil && te.Status == Failed && te.Id == "Build-0" 43 }, 44 }, 45 { 46 description: "deploy failed", 47 phase: constants.Deploy, 48 waitFn: func() bool { 49 handler.logLock.Lock() 50 logEntry := handler.eventLog[len(handler.eventLog)-1] 51 handler.logLock.Unlock() 52 te := logEntry.GetTaskEvent() 53 return te != nil && te.Status == Failed && te.Id == "Deploy-0" 54 }, 55 }, 56 { 57 description: "status check failed", 58 phase: constants.StatusCheck, 59 waitFn: func() bool { 60 handler.logLock.Lock() 61 logEntry := handler.eventLog[len(handler.eventLog)-1] 62 handler.logLock.Unlock() 63 te := logEntry.GetTaskEvent() 64 return te != nil && te.Status == Failed && te.Id == "StatusCheck-0" 65 }, 66 }, 67 } 68 for _, tc := range tcs { 69 t.Run(tc.description, func(t *testing.T) { 70 TaskFailed(tc.phase, errors.New("random error")) 71 wait(t, tc.waitFn) 72 }) 73 } 74 }