@@ -9,6 +9,7 @@ package directory_test
9
9
import (
10
10
"context"
11
11
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
12
+ "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/path"
12
13
"net/http"
13
14
"strconv"
14
15
"testing"
@@ -2528,6 +2529,112 @@ func (s *RecordedTestSuite) TestDirRenameNoOptions() {
2528
2529
_require .NoError (err )
2529
2530
}
2530
2531
2532
+ func (s * RecordedTestSuite ) TestDirRenameWithSpecialCharacters () {
2533
+ _require := require .New (s .T ())
2534
+ testName := s .T ().Name ()
2535
+
2536
+ filesystemName := testcommon .GenerateFileSystemName (testName )
2537
+ fsClient , err := testcommon .GetFileSystemClient (filesystemName , s .T (), testcommon .TestAccountDatalake , nil )
2538
+ _require .NoError (err )
2539
+ defer testcommon .DeleteFileSystem (context .Background (), _require , fsClient )
2540
+
2541
+ _ , err = fsClient .Create (context .Background (), nil )
2542
+ _require .NoError (err )
2543
+
2544
+ // Test with directory name containing spaces
2545
+ dirName := "dir with spaces"
2546
+ dirClient , err := testcommon .GetDirClient (filesystemName , dirName , s .T (), testcommon .TestAccountDatalake , nil )
2547
+ _require .NoError (err )
2548
+
2549
+ resp , err := dirClient .Create (context .Background (), nil )
2550
+ _require .NoError (err )
2551
+ _require .NotNil (resp )
2552
+
2553
+ // Rename to a path with special characters
2554
+ newName := "renamed dir+special@!&% chars"
2555
+ _ , err = dirClient .Rename (context .Background (), newName , nil )
2556
+ _require .NoError (err )
2557
+
2558
+ // Verify new directory exists by creating a client to it and checking properties
2559
+ newClient , err := testcommon .GetDirClient (filesystemName , newName , s .T (), testcommon .TestAccountDatalake , nil )
2560
+ _require .NoError (err )
2561
+
2562
+ _ , err = newClient .GetProperties (context .Background (), nil )
2563
+ _require .NoError (err )
2564
+
2565
+ // Test with Unicode characters
2566
+ unicodeDirName := "lör mapp"
2567
+ unicodeClient , err := testcommon .GetDirClient (filesystemName , unicodeDirName , s .T (), testcommon .TestAccountDatalake , nil )
2568
+ _require .NoError (err )
2569
+
2570
+ resp , err = unicodeClient .Create (context .Background (), nil )
2571
+ _require .NoError (err )
2572
+ _require .NotNil (resp )
2573
+
2574
+ // Rename Unicode directory to another Unicode name
2575
+ newUnicodeName := "ångström ümlaut 目录"
2576
+ _ , err = unicodeClient .Rename (context .Background (), newUnicodeName , nil )
2577
+ _require .NoError (err )
2578
+
2579
+ // Verify new directory exists
2580
+ newUnicodeClient , err := testcommon .GetDirClient (filesystemName , newUnicodeName , s .T (), testcommon .TestAccountDatalake , nil )
2581
+ _require .NoError (err )
2582
+
2583
+ _ , err = newUnicodeClient .GetProperties (context .Background (), nil )
2584
+ _require .NoError (err )
2585
+ }
2586
+
2587
+ func (s * RecordedTestSuite ) TestDirRenameWithQueryParameters () {
2588
+ _require := require .New (s .T ())
2589
+ testName := s .T ().Name ()
2590
+
2591
+ filesystemName := testcommon .GenerateFileSystemName (testName )
2592
+ fsClient , err := testcommon .GetFileSystemClient (filesystemName , s .T (), testcommon .TestAccountDatalake , nil )
2593
+ _require .NoError (err )
2594
+ defer testcommon .DeleteFileSystem (context .Background (), _require , fsClient )
2595
+
2596
+ _ , err = fsClient .Create (context .Background (), nil )
2597
+ _require .NoError (err )
2598
+
2599
+ // Create a regular directory
2600
+ dirName := "original-dir"
2601
+ dirClient , err := testcommon .GetDirClient (filesystemName , dirName , s .T (), testcommon .TestAccountDatalake , nil )
2602
+ _require .NoError (err )
2603
+
2604
+ resp , err := dirClient .Create (context .Background (), nil )
2605
+ _require .NoError (err )
2606
+ _require .NotNil (resp )
2607
+
2608
+ // In a real scenario, SAS tokens or other parameters might be appended to the source path
2609
+ // Here we're simulating this with some fake query parameters
2610
+ srcPathWithQuery := dirName + "?param1=value1¶m2=value with spaces"
2611
+
2612
+ // Create a client with the path including query parameters
2613
+ // Note: This is just to test our URL encoding, in a real scenario you'd get this path from somewhere else
2614
+ _ , err = dirClient .Rename (context .Background (), "new-dir" , nil )
2615
+ _require .NoError (err )
2616
+
2617
+ // Create a new directory to test the rename with query parameters
2618
+ newDir := "query-test-dir"
2619
+ queryClient , err := testcommon .GetDirClient (filesystemName , newDir , s .T (), testcommon .TestAccountDatalake , nil )
2620
+ _require .NoError (err )
2621
+
2622
+ resp , err = queryClient .Create (context .Background (), nil )
2623
+ _require .NoError (err )
2624
+ _require .NotNil (resp )
2625
+
2626
+ // Use internal implementation to test path handling with query parameters
2627
+ // This is a white box test since we can't directly attach query params to the source path in normal usage
2628
+ path := newDir + "?param1=value1¶m2=value with spaces"
2629
+ _ , _ , _ , createOpts , _ := path .FormatRenameOptions (nil , path )
2630
+
2631
+ _require .NotNil (createOpts )
2632
+ _require .NotNil (createOpts .RenameSource )
2633
+ // Verify the source path was properly encoded
2634
+ expected := "query-test-dir?param1=value1¶m2=value+with+spaces"
2635
+ _require .Equal (expected , * createOpts .RenameSource )
2636
+ }
2637
+
2531
2638
func (s * RecordedTestSuite ) TestDirRenameRequestWithCPK () {
2532
2639
_require := require .New (s .T ())
2533
2640
testName := s .T ().Name ()
0 commit comments