当前位置: 首页>>代码示例>>Golang>>正文


Golang gcsutil.CreateObject函数代码示例

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


在下文中一共展示了CreateObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BucketsAreSegregatedByName

func (t *ConnTest) BucketsAreSegregatedByName() {
	const objName = "baz"
	var contents []byte
	var err error

	b0, err := t.conn.OpenBucket(t.ctx, "foo")
	AssertEq(nil, err)

	b1, err := t.conn.OpenBucket(t.ctx, "bar")
	AssertEq(nil, err)

	// Add an object with the same name but different contents to each of two
	// buckets.
	_, err = gcsutil.CreateObject(t.ctx, b0, objName, []byte("taco"))
	AssertEq(nil, err)

	_, err = gcsutil.CreateObject(t.ctx, b1, objName, []byte("burrito"))
	AssertEq(nil, err)

	// Each should have stored it independently.
	contents, err = gcsutil.ReadObject(t.ctx, b0, objName)
	AssertEq(nil, err)
	ExpectEq("taco", string(contents))

	contents, err = gcsutil.ReadObject(t.ctx, b1, objName)
	AssertEq(nil, err)
	ExpectEq("burrito", string(contents))
}
开发者ID:okdave,项目名称:gcloud,代码行数:28,代码来源:conn_test.go

示例2: BackingObjectHasBeenOverwritten_BeforeReading

func (t *IntegrationTest) BackingObjectHasBeenOverwritten_BeforeReading() {
	// Create an object, then create the mutable object wrapper around it.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	t.create(o)

	// Overwrite the GCS object.
	_, err = gcsutil.CreateObject(t.ctx, t.bucket, "foo", "burrito")
	AssertEq(nil, err)

	// Sync doesn't need to do anything.
	rl, newObj, err := t.sync(o)

	AssertEq(nil, err)
	ExpectEq(nil, rl)
	ExpectEq(nil, newObj)

	// Anything that needs to fault in the contents should fail.
	_, err = t.mc.ReadAt(t.ctx, []byte{}, 0)
	ExpectThat(err, Error(HasSubstr("not found")))

	err = t.mc.Truncate(t.ctx, 10)
	ExpectThat(err, Error(HasSubstr("not found")))

	_, err = t.mc.WriteAt(t.ctx, []byte{}, 0)
	ExpectThat(err, Error(HasSubstr("not found")))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:28,代码来源:integration_test.go

示例3: CloneToChildFile_DestinationExists

func (t *DirTest) CloneToChildFile_DestinationExists() {
	const srcName = "blah/baz"
	dstName := path.Join(dirInodeName, "qux")

	var o *gcs.Object
	var err error

	// Create the source.
	src, err := gcsutil.CreateObject(t.ctx, t.bucket, srcName, []byte("taco"))
	AssertEq(nil, err)

	// And a destination object that will be overwritten.
	_, err = gcsutil.CreateObject(t.ctx, t.bucket, dstName, []byte(""))
	AssertEq(nil, err)

	// Call the inode.
	o, err = t.in.CloneToChildFile(t.ctx, path.Base(dstName), src)
	AssertEq(nil, err)
	AssertNe(nil, o)

	ExpectEq(dstName, o.Name)
	ExpectFalse(inode.IsSymlink(o))
	ExpectEq(len("taco"), o.Size)

	// Check resulting contents.
	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, dstName)
	AssertEq(nil, err)
	ExpectEq("taco", string(contents))
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:29,代码来源:dir_test.go

示例4: LookUpChild_ImplicitDirOnly_Enabled

func (t *DirTest) LookUpChild_ImplicitDirOnly_Enabled() {
	const name = "qux"
	objName := path.Join(dirInodeName, name) + "/"

	var err error

	// Enable implicit dirs.
	t.resetInode(true)

	// Create an object that implicitly defines the directory.
	otherObjName := path.Join(objName, "asdf")
	_, err = gcsutil.CreateObject(t.ctx, t.bucket, otherObjName, []byte(""))
	AssertEq(nil, err)

	// Looking up the name should work.
	result, err := t.in.LookUpChild(t.ctx, name)

	AssertEq(nil, err)
	ExpectEq(nil, result.Object)

	ExpectEq(objName, result.FullName)
	ExpectTrue(result.ImplicitDir)

	// A conflict marker should not work.
	result, err = t.in.LookUpChild(t.ctx, name+inode.ConflictingFileNameSuffix)
	AssertEq(nil, err)
	ExpectFalse(result.Exists())
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:28,代码来源:dir_test.go

示例5: LookUpChild_DirOnly

func (t *DirTest) LookUpChild_DirOnly() {
	const name = "qux"
	objName := path.Join(dirInodeName, name) + "/"

	var o *gcs.Object
	var err error

	// Create a backing object.
	createObj, err := gcsutil.CreateObject(t.ctx, t.bucket, objName, []byte(""))
	AssertEq(nil, err)

	// Look up with the proper name.
	result, err := t.in.LookUpChild(t.ctx, name)
	o = result.Object

	AssertEq(nil, err)
	AssertNe(nil, o)

	ExpectEq(objName, result.FullName)
	ExpectEq(objName, o.Name)
	ExpectEq(createObj.Generation, o.Generation)
	ExpectEq(createObj.Size, o.Size)

	// A conflict marker name shouldn't work.
	result, err = t.in.LookUpChild(t.ctx, name+inode.ConflictingFileNameSuffix)
	AssertEq(nil, err)
	ExpectFalse(result.Exists())
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:28,代码来源:dir_test.go

示例6: DeleteObject

func (t *PrefixBucketTest) DeleteObject() {
	var err error
	suffix := "taco"
	name := t.prefix + suffix
	contents := "foobar"

	// Create an object through the back door.
	_, err = gcsutil.CreateObject(t.ctx, t.wrapped, name, []byte(contents))
	AssertEq(nil, err)

	// Delete it.
	err = t.bucket.DeleteObject(
		t.ctx,
		&gcs.DeleteObjectRequest{
			Name: suffix,
		})

	AssertEq(nil, err)

	// It should be gone.
	_, err = t.wrapped.StatObject(
		t.ctx,
		&gcs.StatObjectRequest{
			Name: name,
		})

	ExpectThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:28,代码来源:prefix_bucket_test.go

示例7: SetMtime_SourceObjectGenerationChanged

func (t *FileTest) SetMtime_SourceObjectGenerationChanged() {
	var err error

	// Clobber the backing object.
	newObj, err := gcsutil.CreateObject(
		t.ctx,
		t.bucket,
		t.in.Name(),
		[]byte("burrito"))

	AssertEq(nil, err)

	// Set mtime.
	mtime := time.Now().UTC().Add(123 * time.Second)
	err = t.in.SetMtime(t.ctx, mtime)
	AssertEq(nil, err)

	// The object in the bucket should not have been changed.
	statReq := &gcs.StatObjectRequest{Name: t.in.Name()}
	o, err := t.bucket.StatObject(t.ctx, statReq)

	AssertEq(nil, err)
	ExpectEq(newObj.Generation, o.Generation)
	ExpectEq(0, len(o.Metadata))
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:25,代码来源:file_test.go

示例8: WithinLeaserLimit

func (t *IntegrationTest) WithinLeaserLimit() {
	AssertLt(len("taco"), fileLeaserLimitBytes)

	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	t.create(o)

	// Extend to be up against the leaser limit, then write out to GCS, which
	// should downgrade to a read lease.
	err = t.mc.Truncate(t.ctx, fileLeaserLimitBytes)
	AssertEq(nil, err)

	rl, _, err := t.sync(o)
	AssertEq(nil, err)

	// The backing object should be present and contain the correct contents.
	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, o.Name)
	AssertEq(nil, err)
	ExpectEq(fileLeaserLimitBytes, len(contents))

	// Delete the backing object.
	err = t.bucket.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: o.Name})
	AssertEq(nil, err)

	// We should still be able to read the contents, because the read lease
	// should still be valid.
	buf := make([]byte, 4)
	n, err := rl.ReadAt(buf, 0)

	AssertEq(nil, err)
	ExpectEq("taco", string(buf[0:n]))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:34,代码来源:integration_test.go

示例9: TruncateThenSync

func (t *IntegrationTest) TruncateThenSync() {
	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	t.create(o)

	// Truncate.
	err = t.mc.Truncate(t.ctx, 2)
	AssertEq(nil, err)

	// Sync should save out the new generation.
	rl, newObj, err := t.sync(o)
	AssertEq(nil, err)

	ExpectNe(o.Generation, newObj.Generation)
	ExpectEq(t.objectGeneration("foo"), newObj.Generation)

	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
	AssertEq(nil, err)
	ExpectEq("ta", string(contents))

	// Read via the lease.
	_, err = rl.Seek(0, 0)
	AssertEq(nil, err)

	contents, err = ioutil.ReadAll(rl)
	AssertEq(nil, err)
	ExpectEq("ta", string(contents))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:30,代码来源:integration_test.go

示例10: CopyObject

func (t *PrefixBucketTest) CopyObject() {
	var err error
	suffix := "taco"
	name := t.prefix + suffix
	contents := "foobar"

	// Create an object through the back door.
	_, err = gcsutil.CreateObject(t.ctx, t.wrapped, name, []byte(contents))
	AssertEq(nil, err)

	// Copy it to a new name.
	newSuffix := "burrito"
	o, err := t.bucket.CopyObject(
		t.ctx,
		&gcs.CopyObjectRequest{
			SrcName: suffix,
			DstName: newSuffix,
		})

	AssertEq(nil, err)
	ExpectEq(newSuffix, o.Name)

	// Read it through the back door.
	actual, err := gcsutil.ReadObject(t.ctx, t.wrapped, t.prefix+newSuffix)
	AssertEq(nil, err)
	ExpectEq(contents, string(actual))
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:27,代码来源:prefix_bucket_test.go

示例11: LargerThanLeaserLimit

func (t *IntegrationTest) LargerThanLeaserLimit() {
	AssertLt(len("taco"), fileLeaserLimitBytes)

	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	t.create(o)

	// Extend to be past the leaser limit, then write out to GCS, which should
	// downgrade to a read lease.
	err = t.mc.Truncate(t.ctx, fileLeaserLimitBytes+1)
	AssertEq(nil, err)

	rl, _, err := t.sync(o)
	AssertEq(nil, err)

	// The backing object should be present and contain the correct contents.
	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, o.Name)
	AssertEq(nil, err)
	ExpectEq(fileLeaserLimitBytes+1, len(contents))

	// Delete the backing object.
	err = t.bucket.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: o.Name})
	AssertEq(nil, err)

	// The contents should be lost, because the leaser should have revoked the
	// read lease.
	_, err = rl.ReadAt(make([]byte, len(contents)), 0)
	ExpectThat(err, Error(HasSubstr("revoked")))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:31,代码来源:integration_test.go

示例12: UpdateUpdatesCache

func (t *IntegrationTest) UpdateUpdatesCache() {
	const name = "taco"
	var err error

	// Create an object through the back door.
	_, err = gcsutil.CreateObject(t.ctx, t.wrapped, name, []byte{})
	AssertEq(nil, err)

	// Update it, putting the new version in cache.
	updateReq := &gcs.UpdateObjectRequest{
		Name: name,
	}

	_, err = t.bucket.UpdateObject(t.ctx, updateReq)
	AssertEq(nil, err)

	// Delete the object through the back door.
	err = t.wrapped.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: name})
	AssertEq(nil, err)

	// StatObject should still see it.
	o, err := t.stat(name)
	AssertEq(nil, err)
	ExpectNe(nil, o)
}
开发者ID:okdave,项目名称:gcloud,代码行数:25,代码来源:integration_test.go

示例13: BackingObjectHasBeenDeleted_BeforeReading

func (t *IntegrationTest) BackingObjectHasBeenDeleted_BeforeReading() {
	// Create an object to obtain a record, then delete it.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	err = t.bucket.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: o.Name})
	AssertEq(nil, err)

	// Create a mutable object around it.
	t.create(o)

	// Sync doesn't need to do anything.
	rl, newObj, err := t.sync(o)

	AssertEq(nil, err)
	ExpectEq(nil, rl)
	ExpectEq(nil, newObj)

	// Anything that needs to fault in the contents should fail.
	_, err = t.mc.ReadAt(t.ctx, []byte{}, 0)
	ExpectThat(err, Error(HasSubstr("not found")))

	err = t.mc.Truncate(t.ctx, 10)
	ExpectThat(err, Error(HasSubstr("not found")))

	_, err = t.mc.WriteAt(t.ctx, []byte{}, 0)
	ExpectThat(err, Error(HasSubstr("not found")))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:28,代码来源:integration_test.go

示例14: TruncateThenSync

func (t *IntegrationTest) TruncateThenSync() {
	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", []byte("taco"))
	AssertEq(nil, err)

	t.create(o)

	// Truncate.
	t.clock.AdvanceTime(time.Second)
	truncateTime := t.clock.Now()
	err = t.tf.Truncate(2)
	t.clock.AdvanceTime(time.Second)

	AssertEq(nil, err)

	// Sync should save out the new generation.
	newObj, err := t.sync(o)
	AssertEq(nil, err)

	ExpectNe(o.Generation, newObj.Generation)
	ExpectEq(t.objectGeneration("foo"), newObj.Generation)
	ExpectEq(
		truncateTime.UTC().Format(time.RFC3339Nano),
		newObj.Metadata["gcsfuse_mtime"])

	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
	AssertEq(nil, err)
	ExpectEq("ta", string(contents))
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:29,代码来源:integration_test.go

示例15: UpdateInvalidatesNegativeCache

func (t *IntegrationTest) UpdateInvalidatesNegativeCache() {
	const name = "taco"
	var err error

	// Stat an unknown object, getting it into the negative cache.
	_, err = t.stat(name)
	AssertThat(err, HasSameTypeAs(&gcs.NotFoundError{}))

	// Create the object through the back door.
	_, err = gcsutil.CreateObject(t.ctx, t.wrapped, name, []byte{})
	AssertEq(nil, err)

	// Update the object.
	updateReq := &gcs.UpdateObjectRequest{
		Name: name,
	}

	_, err = t.bucket.UpdateObject(t.ctx, updateReq)
	AssertEq(nil, err)

	// Now StatObject should see it.
	o, err := t.stat(name)
	AssertEq(nil, err)
	ExpectNe(nil, o)
}
开发者ID:okdave,项目名称:gcloud,代码行数:25,代码来源:integration_test.go


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