github.com/hugorut/terraform@v1.1.3/src/getproviders/filesystem_search_test.go (about)

     1  package getproviders
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/hugorut/terraform/src/addrs"
     9  )
    10  
    11  func TestSearchLocalDirectory(t *testing.T) {
    12  	tests := []struct {
    13  		Fixture string
    14  		Subdir  string
    15  		Want    map[addrs.Provider]PackageMetaList
    16  	}{
    17  		{
    18  			"symlinks",
    19  			"symlink",
    20  			map[addrs.Provider]PackageMetaList{
    21  				addrs.MustParseProviderSourceString("example.com/foo/bar"): {
    22  					{
    23  						Provider:       addrs.MustParseProviderSourceString("example.com/foo/bar"),
    24  						Version:        MustParseVersion("1.0.0"),
    25  						TargetPlatform: Platform{OS: "linux", Arch: "amd64"},
    26  						Filename:       "terraform-provider-bar_1.0.0_linux_amd64.zip",
    27  						Location:       PackageLocalDir("testdata/search-local-directory/symlinks/real/example.com/foo/bar/1.0.0/linux_amd64"),
    28  					},
    29  				},
    30  				// This search doesn't find example.net/foo/bar because only
    31  				// the top-level search directory is supported as being a
    32  				// symlink, and so we ignore the example.net symlink to
    33  				// example.com that is one level deeper.
    34  			},
    35  		},
    36  	}
    37  
    38  	for _, test := range tests {
    39  		t.Run(test.Fixture, func(t *testing.T) {
    40  			fullDir := filepath.Join("testdata/search-local-directory", test.Fixture, test.Subdir)
    41  			got, err := SearchLocalDirectory(fullDir)
    42  			if err != nil {
    43  				t.Errorf("unexpected error: %s", err)
    44  			}
    45  			want := test.Want
    46  
    47  			if diff := cmp.Diff(want, got); diff != "" {
    48  				t.Errorf("wrong result\n%s", diff)
    49  			}
    50  		})
    51  	}
    52  }