public void ShowBlobWithLease() { string containerName = Utility.GenNameString("container"); string pageBlobName = Utility.GenNameString("page"); string blockBlobName = Utility.GenNameString("block"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { CloudBlob pageBlob = blobUtil.CreatePageBlob(container, pageBlobName); CloudBlob blockBlob = blobUtil.CreateBlockBlob(container, blockBlobName); ((CloudPageBlob)pageBlob).AcquireLease(null, string.Empty); ((CloudBlockBlob)blockBlob).AcquireLease(null, string.Empty); pageBlob.FetchAttributes(); blockBlob.FetchAttributes(); Test.Assert(nodejsAgent.ShowAzureStorageBlob(pageBlobName, containerName), Utility.GenComparisonData("show blob with lease", true)); nodejsAgent.OutputValidation(new List <CloudBlob>() { pageBlob }); Test.Assert(nodejsAgent.ShowAzureStorageBlob(blockBlobName, containerName), Utility.GenComparisonData("show blob with lease", true)); nodejsAgent.OutputValidation(new List <CloudBlob>() { blockBlob }); } finally { blobUtil.RemoveContainer(containerName); } }
public void ShowBlobWithMetadata() { string containerName = Utility.GenNameString("container"); string pageBlobName = Utility.GenNameString("page"); string blockBlobName = Utility.GenNameString("block"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { CloudBlob pageBlob = blobUtil.CreatePageBlob(container, pageBlobName); CloudBlob blockBlob = blobUtil.CreateBlockBlob(container, blockBlobName); int count = Utility.GetRandomTestCount(); for (int i = 0; i < count; i++) { pageBlob.Metadata.Add(Utility.GenNameString("ShowBlobWithMetadata"), Utility.GenNameString("ShowBlobWithMetadata")); pageBlob.SetMetadata(); blockBlob.Metadata.Add(Utility.GenNameString("ShowBlobWithMetadata"), Utility.GenNameString("ShowBlobWithMetadata")); blockBlob.SetMetadata(); } Test.Assert(nodejsAgent.ShowAzureStorageBlob(pageBlobName, containerName), Utility.GenComparisonData("show blob with metadata", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Expect to retrieve {0} blobs, but retrieved {1} blobs", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <CloudBlob>() { pageBlob }); Test.Assert(nodejsAgent.ShowAzureStorageBlob(blockBlobName, containerName), Utility.GenComparisonData("show blob with metadata", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Expect to retrieve {0} blobs, but retrieved {1} blobs", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <CloudBlob>() { blockBlob }); } finally { blobUtil.RemoveContainer(containerName); } }
public void ShowLogsContainer() { const string containerName = "$logs"; Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, containerName); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetContainerReference(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; //--------------Show operation-------------- Test.Assert(nodejsAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("show $logs container", true)); container.FetchAttributes(); CloudBlobUtil.PackContainerCompareData(container, dic); // Verification for returned values nodejsAgent.OutputValidation(comp); }
public void ShowBlobWithSpecialChars(BlobType blobType) { CloudBlobContainer container = blobUtil.CreateContainer(); string blobName = SpecialChars; CloudBlob blob = blobUtil.CreateBlob(container, blobName, blobType); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { Test.Assert(nodejsAgent.ShowAzureStorageBlob(blobName, container.Name), "show blob name with special chars should succeed"); blob.FetchAttributes(); nodejsAgent.OutputValidation(new List <CloudBlob>() { blob }); } finally { blobUtil.RemoveContainer(container.Name); } }
public void ShowContainerWithSasPolicy() { string containerName = Utility.GenNameString("container"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { TimeSpan sasLifeTime = TimeSpan.FromMinutes(10); BlobContainerPermissions permission = new BlobContainerPermissions(); int count = random.Next(1, 5); for (int i = 0; i < count; i++) { permission.SharedAccessPolicies.Add(Utility.GenNameString("saspolicy"), new SharedAccessBlobPolicy { SharedAccessExpiryTime = DateTime.Now.Add(sasLifeTime), Permissions = SharedAccessBlobPermissions.Read, }); } container.SetPermissions(permission); Test.Assert(nodejsAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("show container", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Create {0} containers, actually retrieved {1} containers", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <BlobContainerPermissions>() { permission }); } finally { blobUtil.RemoveContainer(containerName); } }
/// <summary> /// Functional Cases: /// 1. Upload a new blob file in the root container (Set-AzureStorageBlobContent Positive 2) /// 2. Get an existing blob in the root container (Get-AzureStorageBlob Positive 2) /// 3. Download an existing blob in the root container (Get-AzureStorageBlobContent Positive 2) /// 4. Remove an existing blob in the root container (Remove-AzureStorageBlob Positive 2) /// </summary> internal void RootBlobOperations(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type) { const string ROOT_CONTAINER_NAME = "$root"; string blobName = Path.GetFileName(UploadFilePath); string downloadFilePath = Path.Combine(DownloadDirPath, blobName); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >(); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName); dic["BlobType"] = Type; comp.Add(dic); // create the container CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetRootContainerReference(); container.CreateIfNotExists(); //--------------Upload operation-------------- Test.Assert(agent.SetAzureStorageBlobContent(UploadFilePath, ROOT_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", true)); CloudBlob blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName); blob.FetchAttributes(); // Verification for returned values CloudBlobUtil.PackBlobCompareData(blob, dic); agent.OutputValidation(comp); Test.Assert(blob.Exists(), "blob " + blobName + " should exist!"); // validate the ContentType value for GetAzureStorageBlob operation // Remove the ContentType validation since it's not set/control by PowerShell, and is totally server behavior, and can change with server behavior change. //dic["ContentType"] = "application/octet-stream"; //--------------Get operation-------------- Test.Assert(agent.GetAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", true)); // Verification for returned values agent.OutputValidation(comp); if (agent is NodeJSAgent) { NodeJSAgent nodejsAgent = (NodeJSAgent)agent; //--------------Show operation-------------- Test.Assert(nodejsAgent.ShowAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("ShowAzureStorageBlob", true)); // Verification for returned values nodejsAgent.OutputValidation(comp); } //--------------Download operation-------------- downloadFilePath = Path.Combine(DownloadDirPath, blobName); Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlobContent", true)); // Verification for returned values agent.OutputValidation(comp); Test.Assert(FileUtil.CompareTwoFiles(downloadFilePath, UploadFilePath), String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath)); //--------------Remove operation-------------- Test.Assert(agent.RemoveAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", true)); blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName); Test.Assert(blob == null, "blob {0} should not exist!", blobName); }