• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang memfs.Create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/blang/vfs/memfs.Create函数的典型用法代码示例。如果您正苦于以下问题:Golang Create函数的具体用法?Golang Create怎么用?Golang Create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()))
}
开发者ID:adammck,项目名称:terraform-inventory,代码行数:7,代码来源:input_test.go


示例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"])
}
开发者ID:hairyhenderson,项目名称:gomplate,代码行数:25,代码来源:data_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:26,代码来源:multiple_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:30,代码来源:io_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:30,代码来源:io_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:26,代码来源:io_test.go


示例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)
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:8,代码来源:io_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:9,代码来源:io_test.go


示例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)
}
开发者ID:blang,项目名称:vfs,代码行数:9,代码来源:example_test.go


示例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())
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:12,代码来源:env_test.go


示例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)
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:13,代码来源:env_test.go


示例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)
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:13,代码来源:compare_test.go


示例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)
}
开发者ID:gitter-badger,项目名称:vfs,代码行数:14,代码来源:example_mountfs.go


示例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)
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:14,代码来源:io_test.go


示例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")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:14,代码来源:env_test.go


示例16: TestEnvOneArg

func TestEnvOneArg(t *testing.T) {
	source := &fsRoot{memfs.Create(), "/source"}
	testWrite(t, source, ".template", "key")

	env, err := source.GetEnvironment("key=value")
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(env.Replacements(), []string{"key", "value"}) {
		t.Log(env.Replacements())
		t.Fatal("wrong replacements")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:14,代码来源:env_test.go


示例17: TestIOList

func TestIOList(t *testing.T) {
	target := &fsRoot{memfs.Create(), "/root"}
	testWrite(t, target, "sub1", "hello1")
	testWrite(t, target, "sub2", "hello2")

	list, err := target.List(FilterFileAllowAll)

	if err != nil {
		t.Fatal("list failed", err)
	}

	if !reflect.DeepEqual(list, []string{"/sub1", "/sub2"}) {
		t.Fatal("wrong list", list)
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:15,代码来源:io_test.go


示例18: TestMultiSimpleCreate

func TestMultiSimpleCreate(t *testing.T) {
	mem := memfs.Create()
	source := &fsRoot{mem, "/source"}
	target := &fsRoot{mem, "/target"}

	testWrite(t, source, "template", "hello")

	err := source.Create(Environment(nil), target)
	if err != nil {
		t.Fatal("Template creation failed", err)
	}

	if testRead(t, target, "template") != "hello\n" {
		t.Fatal("Expected hello")
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:16,代码来源:multiple_test.go


示例19: TestWriteFile

func TestWriteFile(t *testing.T) {
	fs := memfs.Create()

	vfs.WriteFile(fs, testpath, testdata, testmode)

	info, err := fs.Stat(testpath)
	if err != nil {
		t.Fatalf("File not created")
	}
	if info.Size() != int64(len(testdata)) {
		t.Fatalf("Bad file size: %d bytes (expected %d)", info.Size(), len(testdata))
	}
	if info.Mode() != testmode {
		t.Fatalf("Bad file mode: %o (expected %o)", info.Mode(), testmode)
	}
}
开发者ID:blang,项目名称:vfs,代码行数:16,代码来源:ioutil_test.go


示例20: TestEnvPropsBasic

func TestEnvPropsBasic(t *testing.T) {
	source := &fsRoot{memfs.Create(), "/source"}
	testWrite(t, source, ".template", "key")

	props, err := envReadProps(source)
	if err != nil {
		t.Fatal(err)
	}

	if len(props) != 1 {
		t.Fatal("expected one entry", props)
	}

	if props["key"] != "" {
		t.Fatal("expected key=\"\"", props["key"])
	}
}
开发者ID:jwiklund,项目名称:tmpl,代码行数:17,代码来源:env_test.go



注:本文中的github.com/blang/vfs/memfs.Create函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang spiffy.DbConnection类代码示例发布时间:2022-05-24
下一篇:
Golang vfs.Filesystem类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap