Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 7 src/corelib/Providers/Rackspace/CloudFilesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,13 @@ public ExtractArchiveResponse ExtractArchive(Stream stream, string uploadPath, A
/// <inheritdoc />
public void MoveObject(string sourceContainer, string sourceObjectName, string destinationContainer, string destinationObjectName, string destinationContentType = null, Dictionary<string, string> headers = null, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
// Do nothing if the source and destination locations are the same. Prevents the object from being deleted accidentally.
var prefix = GetServiceEndpointCloudFiles(identity, region, useInternalUrl);
var src = new Uri($"{prefix}/{_encodeDecodeProvider.UrlEncode(sourceContainer)}/{_encodeDecodeProvider.UrlEncode(sourceObjectName)}");
var dest = new Uri($"{prefix}/{_encodeDecodeProvider.UrlEncode(destinationContainer)}/{_encodeDecodeProvider.UrlEncode(destinationObjectName)}");
if (src == dest)
return;

CopyObject(sourceContainer, sourceObjectName, destinationContainer, destinationObjectName, destinationContentType, headers, region, useInternalUrl, identity);
DeleteObject(sourceContainer, sourceObjectName, headers, true, region, useInternalUrl, identity);
}
Expand Down
86 changes: 86 additions & 0 deletions 86 src/testing/integration/ObjectStorage/CloudFilesProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;
using net.openstack.Core.Exceptions.Response;
using OpenStack;
using Xunit;
using Xunit.Abstractions;

namespace net.openstack.Providers.Rackspace
{
public class CloudFilesTests
{
private const string region = "RegionOne";
private readonly CloudFilesProvider _cloudFiles;

public CloudFilesTests(ITestOutputHelper testLog)
{
var testOutput = new XunitTraceListener(testLog);
Trace.Listeners.Add(testOutput);
OpenStackNet.Tracing.Http.Listeners.Add(testOutput);

var authenticationProvider = TestIdentityProvider.GetIdentityProvider();
authenticationProvider.Authenticate();

_cloudFiles = new CloudFilesProvider(null, authenticationProvider);
}

public void Dispose()
{
Trace.Listeners.Clear();
OpenStackNet.Tracing.Http.Listeners.Clear();
}

[Fact]
public void MoveObject()
{
const string container = "test";
const string fileName = "helloworld.html";
const string backupName = "helloworld.bak";

// Remove old test data
try
{
_cloudFiles.DeleteObject(container, backupName, region: region);
}
catch (ItemNotFoundException)
{
}

// Create test data
_cloudFiles.CreateContainer(container, region: region);
var testObject = new MemoryStream(Encoding.UTF8.GetBytes("hello world"));
_cloudFiles.CreateObject(container, testObject, fileName, region: region);

// Backup the file
_cloudFiles.MoveObject(container, fileName, container, backupName, region: region);

// Verify the file moved
var files = _cloudFiles.ListObjects(container, region: region);
Assert.False(files.Any(f => f.Name == fileName));
Assert.True(files.Any(f => f.Name == backupName));
}

[Fact]
public void MoveObject_ShouldDoNothing_WhenSourceAndDestinationAreTheSame()
{
const string container = "test";
const string filename = "helloworld.html";

// Create test data
_cloudFiles.CreateContainer(container, region: region);
var testObject = new MemoryStream(Encoding.UTF8.GetBytes("hello world"));
_cloudFiles.CreateObject(container, testObject, filename, region: region);

// Move the file to the same location
_cloudFiles.MoveObject(container, filename, container, filename, region: region);

// Verify the file wasn't removed
var files = _cloudFiles.ListObjects(container, region: region);
Assert.True(files.Any(f => f.Name == filename));
}
}
}
1 change: 1 addition & 0 deletions 1 src/testing/integration/OpenStack.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<Compile Include="Identity\v2\IdentityTests.cs" />
<Compile Include="Networking\v2\NetworkingTestDataManager.cs" />
<Compile Include="Networking\v2\NetworkingServiceTests.cs" />
<Compile Include="ObjectStorage\CloudFilesProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\Rackspace\CloudNetworksTests.cs" />
<Compile Include="Providers\Rackspace\CloudServersTests.cs" />
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.