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