File: mapper_test.go

package info (click to toggle)
golang-github-viant-toolbox 0.33.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,280 kB
  • sloc: makefile: 16
file content (39 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package storage_test

import (
	"github.com/stretchr/testify/assert"
	"github.com/viant/toolbox"
	"github.com/viant/toolbox/storage"
	"io/ioutil"
	"os"
	"path"
	"testing"
)

func TestTemplateWriter_GenerateStorageCode(t *testing.T) {

	parent := toolbox.CallerDirectory(3)
	var source = toolbox.FileSchema + path.Join(parent, "test", "source")
	var destination = path.Join("test", "source")
	var target = path.Join(parent, "test", "gen", "source.go")

	parent, _ = path.Split(target)
	toolbox.CreateDirIfNotExist(parent)
	err := storage.GenerateStorageCode(&storage.StorageMapping{
		SourceURL:      source,
		DestinationURI: destination,
		TargetFile:     target,
		TargetPackage:  "gen",
	})
	assert.Nil(t, err)

	reader, err := os.Open(target)
	assert.Nil(t, err)
	defer reader.Close()
	content, err := ioutil.ReadAll(reader)
	if assert.Nil(t, err) {
		textContent := string(content)
		assert.Contains(t, textContent, `err := memStorage.Upload("mem://test/source/file2.txt", bytes.NewReader([]byte`)
	}

}