github.com/viant/toolbox@v0.34.5/storage/mapper_test.go (about) 1 package storage_test 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "github.com/viant/toolbox" 6 "github.com/viant/toolbox/storage" 7 "io/ioutil" 8 "os" 9 "path" 10 "testing" 11 ) 12 13 func TestTemplateWriter_GenerateStorageCode(t *testing.T) { 14 15 parent := toolbox.CallerDirectory(3) 16 var source = toolbox.FileSchema + path.Join(parent, "test", "source") 17 var destination = path.Join("test", "source") 18 var target = path.Join(parent, "test", "gen", "source.go") 19 20 parent, _ = path.Split(target) 21 toolbox.CreateDirIfNotExist(parent) 22 err := storage.GenerateStorageCode(&storage.StorageMapping{ 23 SourceURL: source, 24 DestinationURI: destination, 25 TargetFile: target, 26 TargetPackage: "gen", 27 }) 28 assert.Nil(t, err) 29 30 reader, err := os.Open(target) 31 assert.Nil(t, err) 32 defer reader.Close() 33 content, err := ioutil.ReadAll(reader) 34 if assert.Nil(t, err) { 35 textContent := string(content) 36 assert.Contains(t, textContent, `err := memStorage.Upload("mem://test/source/file2.txt", bytes.NewReader([]byte`) 37 } 38 39 }