本文整理汇总了Golang中github.com/jacobsa/gcloud/gcs/gcsutil.CreateObject函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateObject函数的具体用法?Golang CreateObject怎么用?Golang CreateObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Sync_Clobbered
func (t *FileTest) Sync_Clobbered() {
var err error
// Truncate downward.
err = t.in.Truncate(t.ctx, 2)
AssertEq(nil, err)
// Clobber the backing object.
newObj, err := gcsutil.CreateObject(
t.ctx,
t.bucket,
t.in.Name(),
[]byte("burrito"))
AssertEq(nil, err)
// Sync. The call should succeed, but nothing should change.
err = t.in.Sync(t.ctx)
AssertEq(nil, err)
ExpectEq(t.backingObj.Generation, t.in.SourceGeneration().Object)
ExpectEq(t.backingObj.MetaGeneration, t.in.SourceGeneration().Metadata)
// 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(newObj.Size, o.Size)
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:31,代码来源:file_test.go
示例17: BucketContentsAreStable
func (t *ConnTest) BucketContentsAreStable() {
const bucketName = "foo"
const objName = "bar"
var err error
// Open the bucket.
bucket, err := t.conn.OpenBucket(t.ctx, bucketName)
AssertEq(nil, err)
// Add an object to a bucket.
_, err = gcsutil.CreateObject(
t.ctx,
bucket,
objName,
[]byte("taco"))
AssertEq(nil, err)
// Grab the bucket again. It should still be there.
contents, err := gcsutil.ReadObject(
t.ctx,
bucket,
objName)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
}
开发者ID:okdave,项目名称:gcloud,代码行数:28,代码来源:conn_test.go
示例18: LookUpChild_FileAndDirAndImplicitDir_Enabled
func (t *DirTest) LookUpChild_FileAndDirAndImplicitDir_Enabled() {
const name = "qux"
fileObjName := path.Join(dirInodeName, name)
dirObjName := path.Join(dirInodeName, name) + "/"
var o *gcs.Object
var err error
// Enable implicit dirs.
t.resetInode(true)
// Create backing objects.
fileObj, err := gcsutil.CreateObject(t.ctx, t.bucket, fileObjName, []byte("taco"))
AssertEq(nil, err)
dirObj, err := gcsutil.CreateObject(t.ctx, t.bucket, dirObjName, []byte(""))
AssertEq(nil, err)
// Create an object that implicitly defines the directory.
otherObjName := path.Join(dirInodeName, name) + "/asdf"
_, err = gcsutil.CreateObject(t.ctx, t.bucket, otherObjName, []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(dirObjName, result.FullName)
ExpectEq(dirObjName, o.Name)
ExpectEq(dirObj.Generation, o.Generation)
ExpectEq(dirObj.Size, o.Size)
// Look up with the conflict marker name.
result, err = t.in.LookUpChild(t.ctx, name+inode.ConflictingFileNameSuffix)
o = result.Object
AssertEq(nil, err)
AssertNe(nil, o)
ExpectEq(fileObjName, result.FullName)
ExpectEq(fileObjName, o.Name)
ExpectEq(fileObj.Generation, o.Generation)
ExpectEq(fileObj.Size, o.Size)
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:47,代码来源:dir_test.go
示例19: LookUpChild_TypeCaching
func (t *DirTest) LookUpChild_TypeCaching() {
const name = "qux"
fileObjName := path.Join(dirInodeName, name)
dirObjName := path.Join(dirInodeName, name) + "/"
var o *gcs.Object
var err error
// Create a backing object for a file.
_, err = gcsutil.CreateObject(t.ctx, t.bucket, fileObjName, []byte("taco"))
AssertEq(nil, err)
// Look up; we should get the file.
result, err := t.in.LookUpChild(t.ctx, name)
o = result.Object
AssertEq(nil, err)
AssertNe(nil, o)
ExpectEq(fileObjName, o.Name)
// Create a backing object for a directory.
_, err = gcsutil.CreateObject(t.ctx, t.bucket, dirObjName, []byte("taco"))
AssertEq(nil, err)
// Look up again. Even though the directory should shadow the file, because
// we've cached only seeing the file that's what we should get back.
result, err = t.in.LookUpChild(t.ctx, name)
o = result.Object
AssertEq(nil, err)
AssertNe(nil, o)
ExpectEq(fileObjName, o.Name)
// But after the TTL expires, the behavior should flip.
t.clock.AdvanceTime(typeCacheTTL + time.Millisecond)
result, err = t.in.LookUpChild(t.ctx, name)
o = result.Object
AssertEq(nil, err)
AssertNe(nil, o)
ExpectEq(dirObjName, o.Name)
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:46,代码来源:dir_test.go
示例20: BackingObjectHasBeenOverwritten_AfterReading
func (t *IntegrationTest) BackingObjectHasBeenOverwritten_AfterReading() {
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
t.create(o)
// Fault in the contents.
_, err = t.mc.ReadAt(t.ctx, []byte{}, 0)
AssertEq(nil, err)
// Overwrite the backing object.
_, err = gcsutil.CreateObject(t.ctx, t.bucket, "foo", "burrito")
AssertEq(nil, err)
// Reading and modications should still work.
_, err = t.mc.ReadAt(t.ctx, []byte{}, 0)
AssertEq(nil, err)
_, err = t.mc.WriteAt(t.ctx, []byte("a"), 0)
AssertEq(nil, err)
truncateTime := t.clock.Now()
err = t.mc.Truncate(t.ctx, 3)
AssertEq(nil, err)
t.clock.AdvanceTime(time.Second)
// Stat should see the current state.
sr, err := t.mc.Stat(t.ctx)
AssertEq(nil, err)
ExpectEq(3, sr.Size)
ExpectEq(0, sr.DirtyThreshold)
ExpectThat(sr.Mtime, Pointee(timeutil.TimeEq(truncateTime)))
// Sync should fail with a precondition error.
_, _, err = t.sync(o)
ExpectThat(err, HasSameTypeAs(&gcs.PreconditionError{}))
// The newer version should still be present.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, o.Name)
AssertEq(nil, err)
ExpectEq("burrito", string(contents))
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:44,代码来源:integration_test.go
注:本文中的github.com/jacobsa/gcloud/gcs/gcsutil.CreateObject函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论