github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/initializer/init_problems_test.go (about)

     1  /*
     2  Copyright 2020 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 initializer
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	"google.golang.org/protobuf/testing/protocmp"
    24  
    25  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
    26  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
    27  	sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
    28  	"github.com/GoogleContainerTools/skaffold/proto/v1"
    29  	"github.com/GoogleContainerTools/skaffold/testutil"
    30  )
    31  
    32  func TestInitProblems(t *testing.T) {
    33  	initTestCases := []struct {
    34  		description string
    35  		opts        config.SkaffoldOptions
    36  		phase       constants.Phase
    37  		context     *config.ContextConfig
    38  		err         error
    39  		expected    string
    40  		expectedAE  *proto.ActionableErr
    41  	}{
    42  		{
    43  			description: "creating tagger error",
    44  			context:     &config.ContextConfig{},
    45  			phase:       constants.Init,
    46  			err:         fmt.Errorf("creating tagger: something went wrong"),
    47  			expected:    "creating tagger: something went wrong. If above error is unexpected, please open an issue to report this error at https://github.com/GoogleContainerTools/skaffold/issues/new.",
    48  			expectedAE: &proto.ActionableErr{
    49  				ErrCode:     proto.StatusCode_INIT_CREATE_TAGGER_ERROR,
    50  				Message:     "creating tagger: something went wrong",
    51  				Suggestions: sErrors.ReportIssueSuggestion(nil),
    52  			},
    53  		},
    54  		{
    55  			description: "minikube not started error",
    56  			context:     &config.ContextConfig{},
    57  			phase:       constants.Init,
    58  			err:         fmt.Errorf("creating runner: creating builder: getting docker client: getting minikube env: running [/Users/tejaldesai/Downloads/google-cloud-sdk2/bin/minikube docker-env --shell none -p minikube]\n - stdout: \"* The control plane node must be running for this command\\n  - To fix this, run: \\\"minikube start\\\"\\n\"\n - stderr: \"\"\n - cause: exit status 89"),
    59  			expected:    "minikube is probably not running. Try running \"minikube start\".",
    60  			expectedAE: &proto.ActionableErr{
    61  				ErrCode: proto.StatusCode_INIT_MINIKUBE_NOT_RUNNING_ERROR,
    62  				Message: "creating runner: creating builder: getting docker client: getting minikube env: running [/Users/tejaldesai/Downloads/google-cloud-sdk2/bin/minikube docker-env --shell none -p minikube]\n - stdout: \"* The control plane node must be running for this command\\n  - To fix this, run: \\\"minikube start\\\"\\n\"\n - stderr: \"\"\n - cause: exit status 89",
    63  				Suggestions: []*proto.Suggestion{{
    64  					SuggestionCode: proto.SuggestionCode_START_MINIKUBE,
    65  					Action:         "Try running \"minikube start\"",
    66  				}},
    67  			},
    68  		},
    69  		{
    70  			description: "create builder error",
    71  			context:     &config.ContextConfig{},
    72  			phase:       constants.Init,
    73  			err:         fmt.Errorf("creating runner: creating builder: something went wrong"),
    74  			expected:    "creating runner: creating builder: something went wrong. If above error is unexpected, please open an issue to report this error at https://github.com/GoogleContainerTools/skaffold/issues/new.",
    75  			expectedAE: &proto.ActionableErr{
    76  				ErrCode:     proto.StatusCode_INIT_CREATE_BUILDER_ERROR,
    77  				Message:     "creating runner: creating builder: something went wrong",
    78  				Suggestions: sErrors.ReportIssueSuggestion(nil),
    79  			},
    80  		},
    81  		{
    82  			description: "build dependency error",
    83  			context:     &config.ContextConfig{},
    84  			phase:       constants.Init,
    85  			err:         fmt.Errorf("creating runner: unexpected artifact type `DockerrArtifact`"),
    86  			expected:    "creating runner: unexpected artifact type `DockerrArtifact`. If above error is unexpected, please open an issue to report this error at https://github.com/GoogleContainerTools/skaffold/issues/new.",
    87  			expectedAE: &proto.ActionableErr{
    88  				ErrCode:     proto.StatusCode_INIT_CREATE_ARTIFACT_DEP_ERROR,
    89  				Message:     "creating runner: unexpected artifact type `DockerrArtifact`",
    90  				Suggestions: sErrors.ReportIssueSuggestion(nil),
    91  			},
    92  		},
    93  		{
    94  			description: "test dependency error",
    95  			context:     &config.ContextConfig{},
    96  			phase:       constants.Init,
    97  			err:         fmt.Errorf("creating runner: expanding test file paths: .src/test"),
    98  			expected:    "creating runner: expanding test file paths: .src/test. If above error is unexpected, please open an issue to report this error at https://github.com/GoogleContainerTools/skaffold/issues/new.",
    99  			expectedAE: &proto.ActionableErr{
   100  				ErrCode:     proto.StatusCode_INIT_CREATE_TEST_DEP_ERROR,
   101  				Message:     "creating runner: expanding test file paths: .src/test",
   102  				Suggestions: sErrors.ReportIssueSuggestion(nil),
   103  			},
   104  		},
   105  		{
   106  			description: "init cache error",
   107  			context:     &config.ContextConfig{},
   108  			phase:       constants.Init,
   109  			err:         fmt.Errorf("creating runner: initializing cache at some error"),
   110  			expected:    "creating runner: initializing cache at some error. If above error is unexpected, please open an issue to report this error at https://github.com/GoogleContainerTools/skaffold/issues/new.",
   111  			expectedAE: &proto.ActionableErr{
   112  				ErrCode:     proto.StatusCode_INIT_CACHE_ERROR,
   113  				Message:     "creating runner: initializing cache at some error",
   114  				Suggestions: sErrors.ReportIssueSuggestion(nil),
   115  			},
   116  		},
   117  	}
   118  	for _, test := range initTestCases {
   119  		testutil.Run(t, test.description, func(t *testutil.T) {
   120  			t.Override(&sErrors.GetProblemCatalogCopy, func() sErrors.ProblemCatalog {
   121  				pc := sErrors.NewProblemCatalog()
   122  				pc.AddPhaseProblems(constants.Init, problems)
   123  				return pc
   124  			})
   125  			actual := sErrors.ShowAIError(nil, test.err)
   126  			t.CheckDeepEqual(test.expected, actual.Error())
   127  			actualAE := sErrors.ActionableErr(nil, constants.Init, test.err)
   128  			t.CheckDeepEqual(test.expectedAE, actualAE, protocmp.Transform())
   129  		})
   130  	}
   131  }