github.com/hashicorp/go-getter/v2@v2.2.2/folder_storage_test.go (about) 1 package getter 2 3 import ( 4 "context" 5 "os" 6 "path/filepath" 7 "testing" 8 9 testing_helper "github.com/hashicorp/go-getter/v2/helper/testing" 10 ) 11 12 func TestFolderStorage_impl(t *testing.T) { 13 var _ Storage = new(FolderStorage) 14 } 15 16 func TestFolderStorage(t *testing.T) { 17 s := &FolderStorage{StorageDir: testing_helper.TempDir(t)} 18 ctx := context.Background() 19 20 module := testModule("basic") 21 22 // A module shouldn't exist at first... 23 _, ok, err := s.Dir(module) 24 if err != nil { 25 t.Fatalf("err: %s", err) 26 } 27 if ok { 28 t.Fatal("should not exist") 29 } 30 31 key := "foo" 32 33 // We can get it 34 err = s.Get(ctx, key, module, false) 35 if err != nil { 36 t.Fatalf("err: %s", err) 37 } 38 39 // Now the module exists 40 dir, ok, err := s.Dir(key) 41 if err != nil { 42 t.Fatalf("err: %s", err) 43 } 44 if !ok { 45 t.Fatal("should exist") 46 } 47 48 mainPath := filepath.Join(dir, "main.tf") 49 if _, err := os.Stat(mainPath); err != nil { 50 t.Fatalf("err: %s", err) 51 } 52 }