github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/event/v2/status_check_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 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 23 proto "github.com/GoogleContainerTools/skaffold/proto/v2" 24 ) 25 26 func TestResourceStatusCheckEventUpdated(t *testing.T) { 27 defer func() { handler = newHandler() }() 28 29 handler = newHandler() 30 handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) 31 32 wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) 33 ResourceStatusCheckEventUpdated("ns:pod/foo", &proto.ActionableErr{ 34 ErrCode: 509, 35 Message: "image pull error", 36 }) 37 wait(t, func() bool { return handler.getState().StatusCheckState.Resources["ns:pod/foo"] == InProgress }) 38 } 39 40 func TestResourceStatusCheckEventSucceeded(t *testing.T) { 41 defer func() { handler = newHandler() }() 42 43 handler = newHandler() 44 handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) 45 46 wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) 47 resourceStatusCheckEventSucceeded("ns:pod/foo") 48 wait(t, func() bool { return handler.getState().StatusCheckState.Resources["ns:pod/foo"] == Succeeded }) 49 } 50 51 func TestResourceStatusCheckEventFailed(t *testing.T) { 52 defer func() { handler = newHandler() }() 53 54 handler = newHandler() 55 handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) 56 57 wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) 58 resourceStatusCheckEventFailed("ns:pod/foo", &proto.ActionableErr{ 59 ErrCode: 309, 60 Message: "one or more deployments failed", 61 }) 62 wait(t, func() bool { return handler.getState().StatusCheckState.Resources["ns:pod/foo"] == Failed }) 63 }