本文整理汇总了Golang中github.com/blang/vfs/memfs.Create函数的典型用法代码示例。如果您正苦于以下问题:Golang Create函数的具体用法?Golang Create怎么用?Golang Create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetInputPath
func TestGetInputPath(t *testing.T) {
assert.Equal(t, "", GetInputPath(memfs.Create(), venv.Mock()))
assert.Equal(t, "aaa", GetInputPath(memfs.Create(), envWith(map[string]string{"TF_STATE": "aaa"})))
assert.Equal(t, "bbb", GetInputPath(memfs.Create(), envWith(map[string]string{"TI_TFSTATE": "bbb"})))
assert.Equal(t, "terraform.tfstate", GetInputPath(fsWithFiles([]string{"terraform.tfstate"}), venv.Mock()))
assert.Equal(t, ".terraform/terraform.tfstate", GetInputPath(fsWithFiles([]string{".terraform/terraform.tfstate"}), venv.Mock()))
}
示例2: TestDatasource
func TestDatasource(t *testing.T) {
fs := memfs.Create()
fs.Mkdir("/tmp", 0777)
f, _ := vfs.Create(fs, "/tmp/foo.json")
f.Write([]byte(`{"hello":"world"}`))
sources := make(map[string]*Source)
sources["foo"] = &Source{
Alias: "foo",
URL: &url.URL{
Scheme: "file",
Path: "/tmp/foo.json",
},
Ext: "json",
Type: "application/json",
FS: fs,
}
data := &Data{
Sources: sources,
}
expected := make(map[string]interface{})
expected["hello"] = "world"
actual := data.Datasource("foo")
assert.Equal(t, expected["hello"], actual["hello"])
}
示例3: TestMultiProperties
func TestMultiProperties(t *testing.T) {
mem := memfs.Create()
source := &fsRoot{mem, "/source"}
target := &fsRoot{mem, "/source"}
testWrite(t, source, ".template", "PROPERTY1\nPROPERTY2")
testWrite(t, source, "template1", "hello PROPERTY1")
testWrite(t, source, "template2", "hello PROPERTY2")
err := source.Create(Environment(map[string]string{
"PROPERTY1": "property1",
"PROPERTY2": "property2",
}), target)
if err != nil {
t.Fatal(err)
}
if testRead(t, target, "template1") != "hello property1\n" {
t.Fatal("wrong property1")
}
if testRead(t, target, "template2") != "hello property2\n" {
t.Fatal("wrong property2")
}
}
示例4: TestIOReadFile
func TestIOReadFile(t *testing.T) {
fs := memfs.Create()
fs.Mkdir("/root", 0775)
file, err := fs.OpenFile("/root/file", os.O_WRONLY|os.O_CREATE, 0664)
if err != nil {
t.Fatal("could not create test file", err)
}
_, err = file.Write([]byte("hello"))
if err != nil {
t.Fatal("could not write test file", err)
}
target := fsRoot{fs, "/root"}
reader, err := target.Reader("file")
if err != nil {
t.Fatal("could not create reader")
}
var buf bytes.Buffer
_, err = buf.ReadFrom(reader)
if err != nil {
t.Fatal("failed reading", err)
}
if buf.String() != "hello" {
t.Log(buf.String())
t.Fatal("expected hello")
}
}
示例5: TestIOWriteFile
func TestIOWriteFile(t *testing.T) {
fs := memfs.Create()
target := fsRoot{fs, "/root"}
writer, err := target.Writer("file")
if err != nil {
t.Fatal("Could not get writer", err)
}
_, err = writer.Write([]byte("hello"))
if err != nil {
t.Fatal("Could not write", err)
}
file, err := fs.OpenFile("/root/file", os.O_RDONLY, 0)
if err != nil {
t.Fatal("File not created", err)
}
var buf bytes.Buffer
_, err = buf.ReadFrom(file)
if err != nil {
t.Fatal("Failed reading", err)
}
if buf.String() != "hello" {
t.Log(buf.String())
t.Fatal("expected hello")
}
}
示例6: TestIOListRead
func TestIOListRead(t *testing.T) {
target := &fsRoot{memfs.Create(), "/root"}
testWrite(t, target, "sub1", "hello")
list, err := target.List(FilterFileAllowAll)
if err != nil {
t.Fatal("list failed", err)
}
if len(list) != 1 {
t.Fatal("wrong list", list)
}
reader, err := target.Reader(list[0])
if err != nil {
t.Fatal(err)
}
var bytes bytes.Buffer
bytes.ReadFrom(reader)
if bytes.String() != "hello" {
t.Log(bytes.String())
t.Fatal("wrong result")
}
}
示例7: TestIOReadMissing
func TestIOReadMissing(t *testing.T) {
target := fsRoot{memfs.Create(), "/root"}
_, err := target.Reader("file")
if err != notFound {
t.Fatal("expected not found", err)
}
}
示例8: TestIORestrict
func TestIORestrict(t *testing.T) {
target := &fsRoot{memfs.Create(), "/"}
testWrite(t, target, "sub1/leaf1", "hello")
restricted := target.Restrict("sub1")
if testRead(t, restricted, "leaf1") != "hello" {
t.Fatal("expected hello")
}
}
示例9: ExampleMemFS
func ExampleMemFS() {
// Create a fully writable filesystem in memory
fs := memfs.Create()
// Like every other vfs.Filesytem, it could be wrapped, e.g. read-only:
// fs = vfs.ReadOnly(fs)
// The memory fs is completely empty, permissions are supported (e.g. Stat()) but have no effect.
fs.Mkdir("/tmp", 0777)
}
示例10: TestEnvNoArgs
func TestEnvNoArgs(t *testing.T) {
source := &fsRoot{memfs.Create(), "/source"}
env, err := source.GetEnvironment()
if err != nil {
t.Fatal(err)
}
if len(env.Replacements()) != 0 {
t.Fatal("wrong replacements", env.Replacements())
}
}
示例11: TestEnvMissingArg
func TestEnvMissingArg(t *testing.T) {
source := &fsRoot{memfs.Create(), "/source"}
testWrite(t, source, ".template", "key")
_, err := source.GetEnvironment()
if err == nil {
t.Fatal("Expected missing property")
}
if strings.Index(err.Error(), "key") == -1 {
t.Fatal("Wrong error, expected missing 'key'", err)
}
}
示例12: TestCompareSelfNoProperties
func TestCompareSelfNoProperties(t *testing.T) {
fs := &fsRoot{memfs.Create(), "/"}
testWrite(t, fs, "test", "value")
env, err := fs.Compare(nil, fs)
if err != nil {
t.Fatal(err)
}
if len(env) != 0 {
t.Fatal("Expected no env", env)
}
}
示例13: ExampleMountFS
func ExampleMountFS() {
// Create a vfs supporting mounts
// The root fs is accessing the filesystem of the underlying OS
fs := mountfs.Create(vfs.OS())
// Mount a memfs inside
fs.Mount(memfs.Create(), "/memfs")
// This will create /testdir inside the memfs
fs.Mkdir("/memfs/testdir", 0777)
// This will create /tmp/testdir inside your OS fs
fs.Mkdir("/tmp/testdir", 0777)
}
示例14: TestIOListEmpty
func TestIOListEmpty(t *testing.T) {
fs := memfs.Create()
fs.Mkdir("/root", 0775)
target := fsRoot{fs, "/root"}
list, err := target.List(FilterFileAllowAll)
if err != nil {
t.Fatal("list failed", err)
}
if len(list) != 0 {
t.Fatal("expected no entries", list)
}
}
示例15: TestEnvArgWithDefault
func TestEnvArgWithDefault(t *testing.T) {
source := &fsRoot{memfs.Create(), "/source"}
testWrite(t, source, ".template", "key [default value]\nother something else")
env, err := source.GetEnvironment("other=value")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(env.Replacements(), []string{"key", "value", "other", "value"}) {
t.Log(env.Replacements())
t.Fatal("wrong replacements")
}
}