github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/workdir/plugin_dirs_test.go (about) 1 package workdir 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 ) 9 10 func TestDirForcedPluginDirs(t *testing.T) { 11 tmpDir := t.TempDir() 12 13 dir := NewDir(tmpDir) 14 // We'll use the default convention of a data dir nested inside the 15 // working directory, so we don't need to override anything on "dir". 16 17 want := []string(nil) 18 got, err := dir.ForcedPluginDirs() 19 if err != nil { 20 t.Fatal(err) 21 } 22 if diff := cmp.Diff(want, got); diff != "" { 23 t.Errorf("wrong initial settings\n%s", diff) 24 } 25 26 fakeDir1 := filepath.Join(tmpDir, "boop1") 27 fakeDir2 := filepath.Join(tmpDir, "boop2") 28 err = dir.SetForcedPluginDirs([]string{fakeDir1, fakeDir2}) 29 if err != nil { 30 t.Fatal(err) 31 } 32 33 want = []string{fakeDir1, fakeDir2} 34 got, err = dir.ForcedPluginDirs() 35 if err != nil { 36 t.Fatal(err) 37 } 38 if diff := cmp.Diff(want, got); diff != "" { 39 t.Errorf("wrong updated settings\n%s", diff) 40 } 41 42 err = dir.SetForcedPluginDirs(nil) 43 if err != nil { 44 t.Fatal(err) 45 } 46 47 want = nil 48 got, err = dir.ForcedPluginDirs() 49 if err != nil { 50 t.Fatal(err) 51 } 52 if diff := cmp.Diff(want, got); diff != "" { 53 t.Errorf("wrong final settings, after reverting back to defaults\n%s", diff) 54 } 55 }