github.com/GoogleContainerTools/skaffold/v2@v2.13.2/pkg/diag/recommender/recommender_test.go (about) 1 /* 2 Copyright 2022 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 recommender 18 19 import ( 20 "testing" 21 22 "github.com/google/go-cmp/cmp" 23 "google.golang.org/protobuf/testing/protocmp" 24 25 "github.com/GoogleContainerTools/skaffold/v2/proto/v1" 26 "github.com/GoogleContainerTools/skaffold/v2/testutil" 27 ) 28 29 func TestContainerErrorMake(t *testing.T) { 30 tests := []struct { 31 description string 32 errCode proto.StatusCode 33 expected *proto.Suggestion 34 }{ 35 { 36 description: "makes err suggestion for terminated containers (303)", 37 errCode: proto.StatusCode_STATUSCHECK_CONTAINER_TERMINATED, 38 expected: &proto.Suggestion{ 39 SuggestionCode: proto.SuggestionCode_CHECK_CONTAINER_LOGS, 40 Action: "Try checking container logs", 41 }, 42 }, 43 { 44 description: "makes err suggestion unhealthy status check (357)", 45 errCode: proto.StatusCode_STATUSCHECK_UNHEALTHY, 46 expected: &proto.Suggestion{ 47 SuggestionCode: proto.SuggestionCode_CHECK_READINESS_PROBE, 48 Action: "Try checking container config `readinessProbe`", 49 }, 50 }, 51 { 52 description: "makes err suggestion for failed image pulls (300)", 53 errCode: proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR, 54 expected: &proto.Suggestion{ 55 SuggestionCode: proto.SuggestionCode_CHECK_CONTAINER_IMAGE, 56 Action: "Try checking container config `image`", 57 }, 58 }, 59 { 60 description: "returns nil suggestion if no case matches", 61 errCode: proto.StatusCode_BUILD_CANCELLED, 62 expected: &NilSuggestion, 63 }, 64 } 65 66 for _, test := range tests { 67 testutil.Run(t, test.description, func(t *testutil.T) { 68 t.CheckDeepEqual( 69 test.expected, 70 ContainerError{}.Make(test.errCode), 71 cmp.AllowUnexported(proto.Suggestion{}), 72 protocmp.Transform(), 73 ) 74 }) 75 } 76 }