コード例 #1
0
ファイル: StorageClassTest.cs プロジェクト: greggaba/GCDotNet
        public void CreateBucketAndObjects()
        {
            // Note: this test may fail if the project location prevents multi-regional storage.
            string initialBucketStorageClass = StorageClasses.MultiRegional;
            string updatedObjectStorageClass = StorageClasses.Coldline;
            string updatedBucketStorageClass = StorageClasses.Nearline;

            string bucketName = _fixture.BucketPrefix + "storage-classes";
            string objectName = TestHelpers.GenerateName();
            var    client     = _fixture.Client;

            client.CreateBucket(_fixture.ProjectId, new Bucket {
                Name = bucketName, StorageClass = initialBucketStorageClass
            });
            _fixture.RegisterBucketToDelete(bucketName);

            var bucket = client.GetBucket(bucketName);

            Assert.Equal(initialBucketStorageClass, bucket.StorageClass);

            var obj = client.UploadObject(bucketName, objectName, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(initialBucketStorageClass, obj.StorageClass);

            // Change storage class via a rewrite
            var options = new CopyObjectOptions
            {
                ExtraMetadata = new Object {
                    StorageClass = updatedObjectStorageClass
                }
            };

            client.CopyObject(bucketName, objectName, bucketName, objectName, options);

            // Fetch separately rather than trusting the return value of CopyObject...
            obj = client.GetObject(bucketName, objectName);
            Assert.Equal(updatedObjectStorageClass, obj.StorageClass);

            bucket.StorageClass = updatedBucketStorageClass;
            client.UpdateBucket(bucket);
            string objectName2 = TestHelpers.GenerateName();

            var obj2 = client.UploadObject(bucketName, objectName2, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(updatedBucketStorageClass, obj2.StorageClass);
        }