github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/buildpacks/dependencies_test.go (about)

     1  /*
     2  Copyright 2019 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 buildpacks
    18  
    19  import (
    20  	"context"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
    25  	"github.com/GoogleContainerTools/skaffold/testutil"
    26  )
    27  
    28  func TestGetDependencies(t *testing.T) {
    29  	tests := []struct {
    30  		description string
    31  		paths       []string
    32  		ignore      []string
    33  		expected    []string
    34  		shouldErr   bool
    35  	}{
    36  		{
    37  			description: "watch everything",
    38  			paths:       []string{"."},
    39  			expected:    []string{"bar", filepath.FromSlash("baz/file"), "foo"},
    40  		},
    41  		{
    42  			description: "watch nothing",
    43  		},
    44  		{
    45  			description: "ignore some paths",
    46  			paths:       []string{"."},
    47  			ignore:      []string{"b*"},
    48  			expected:    []string{"foo"},
    49  		},
    50  		{
    51  			description: "glob",
    52  			paths:       []string{"**"},
    53  			expected:    []string{"bar", filepath.FromSlash("baz/file"), "foo"},
    54  		},
    55  		{
    56  			description: "error",
    57  			paths:       []string{"unknown"},
    58  			shouldErr:   true,
    59  		},
    60  	}
    61  	for _, test := range tests {
    62  		testutil.Run(t, test.description, func(t *testutil.T) {
    63  			// Directory structure:
    64  			//   foo
    65  			//   bar
    66  			// - baz
    67  			//     file
    68  			tmpDir := t.NewTempDir().
    69  				Touch("foo", "bar", "baz/file")
    70  
    71  			deps, err := GetDependencies(context.Background(), tmpDir.Root(), &latest.BuildpackArtifact{
    72  				Dependencies: &latest.BuildpackDependencies{
    73  					Paths:  test.paths,
    74  					Ignore: test.ignore,
    75  				},
    76  			})
    77  
    78  			t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, deps)
    79  		})
    80  	}
    81  }