github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/initializer/analyze/config_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 analyze
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/GoogleContainerTools/skaffold/testutil"
    24  )
    25  
    26  func TestConfigAnalyzer(t *testing.T) {
    27  	tests := []struct {
    28  		name      string
    29  		inputFile string
    30  		analyzer  skaffoldConfigAnalyzer
    31  		shouldErr bool
    32  	}{
    33  		{
    34  			name:      "not skaffold config",
    35  			inputFile: "../testdata/init/hello/main.go",
    36  			analyzer:  skaffoldConfigAnalyzer{},
    37  			shouldErr: false,
    38  		},
    39  		{
    40  			name:      "skaffold config equals target config",
    41  			inputFile: "../testdata/init/hello/skaffold.yaml",
    42  			analyzer: skaffoldConfigAnalyzer{
    43  				targetConfig: "../testdata/init/hello/skaffold.yaml",
    44  			},
    45  			shouldErr: true,
    46  		},
    47  		{
    48  			name:      "skaffold config does not equal target config",
    49  			inputFile: "../testdata/init/hello/skaffold.yaml",
    50  			analyzer: skaffoldConfigAnalyzer{
    51  				targetConfig: "../testdata/init/hello/skaffold.yaml.out",
    52  			},
    53  			shouldErr: false,
    54  		},
    55  		{
    56  			name:      "force overrides",
    57  			inputFile: "../testdata/init/hello/skaffold.yaml",
    58  			analyzer: skaffoldConfigAnalyzer{
    59  				force:        true,
    60  				targetConfig: "../testdata/init/hello/skaffold.yaml",
    61  			},
    62  			shouldErr: false,
    63  		},
    64  		{
    65  			name:      "analyze mode can skip writing, no error",
    66  			inputFile: "../testdata/init/hello/skaffold.yaml",
    67  			analyzer: skaffoldConfigAnalyzer{
    68  				force:        false,
    69  				analyzeMode:  true,
    70  				targetConfig: testutil.Abs(t, "../testdata/init/hello/skaffold.yaml"),
    71  			},
    72  			shouldErr: false,
    73  		},
    74  	}
    75  
    76  	for _, test := range tests {
    77  		testutil.Run(t, test.name, func(t *testutil.T) {
    78  			err := test.analyzer.analyzeFile(context.Background(), test.inputFile)
    79  			t.CheckError(test.shouldErr, err)
    80  		})
    81  	}
    82  }