當前位置: 首頁>>代碼示例>>Golang>>正文


Golang memfs.Create函數代碼示例

本文整理匯總了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()))
}
開發者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


注:本文中的github.com/blang/vfs/memfs.Create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。