|
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | 7 | "math/rand" |
| 8 | + "reflect" |
8 | 9 | "regexp" |
9 | 10 | "strconv" |
10 | 11 | "sync" |
@@ -802,7 +803,7 @@ func TestCreateVolume(t *testing.T) { |
802 | 803 | } |
803 | 804 |
|
804 | 805 | if driver.tags["cluster"] != "efs" || driver.tags["tag2:name2"] != "tag2:val2" { |
805 | | - t.Fatalf("Incorrect tags") |
| 806 | + t.Fatalf("Incorrect tags %v", driver.tags) |
806 | 807 | } |
807 | 808 |
|
808 | 809 | req := &csi.CreateVolumeRequest{ |
@@ -862,7 +863,7 @@ func TestCreateVolume(t *testing.T) { |
862 | 863 | cloud: mockCloud, |
863 | 864 | gidAllocator: NewGidAllocator(), |
864 | 865 | lockManager: NewLockManagerMap(), |
865 | | - tags: parseTagsFromStr("cluster-efs"), |
| 866 | + tags: parseTagsFromStr("cluster-efs:value1:value2"), |
866 | 867 | } |
867 | 868 |
|
868 | 869 | req := &csi.CreateVolumeRequest{ |
@@ -4844,6 +4845,90 @@ func TestControllerGetCapabilities(t *testing.T) { |
4844 | 4845 | } |
4845 | 4846 | } |
4846 | 4847 |
|
| 4848 | +func TestTaggingCapabilitites(t *testing.T) { |
| 4849 | + testCases := []struct { |
| 4850 | + name string |
| 4851 | + testFunc func(t *testing.T) |
| 4852 | + }{ |
| 4853 | + { |
| 4854 | + name: "Success: complex split key value colon with backslash", |
| 4855 | + testFunc: func(t *testing.T) { |
| 4856 | + given := "aa\\:bb cc\\\\dd:ee\\:ff gg\\\\hh" |
| 4857 | + expected := []string{"aa:bb cc\\dd", "ee:ff gg\\hh"} |
| 4858 | + result := splitToList(given, byte(':')) |
| 4859 | + if !reflect.DeepEqual(result, expected) { |
| 4860 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4861 | + } |
| 4862 | + }, |
| 4863 | + }, |
| 4864 | + { |
| 4865 | + name: "Success: complex split key only colon with backslash", |
| 4866 | + testFunc: func(t *testing.T) { |
| 4867 | + given := "aa\\:bb cc\\\\dd\\\\" |
| 4868 | + expected := []string{"aa:bb cc\\dd\\"} |
| 4869 | + result := splitToList(given, byte(':')) |
| 4870 | + if !reflect.DeepEqual(result, expected) { |
| 4871 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4872 | + } |
| 4873 | + }, |
| 4874 | + }, |
| 4875 | + { |
| 4876 | + name: "Success: simple split whitespace", |
| 4877 | + testFunc: func(t *testing.T) { |
| 4878 | + given := "aa:bb cc:dd ee:ff" |
| 4879 | + expected := []string{"aa:bb", "cc:dd", "ee:ff"} |
| 4880 | + result := splitToList(given, byte(' ')) |
| 4881 | + if !reflect.DeepEqual(result, expected) { |
| 4882 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4883 | + } |
| 4884 | + }, |
| 4885 | + }, |
| 4886 | + { |
| 4887 | + name: "Success: simple single tag", |
| 4888 | + testFunc: func(t *testing.T) { |
| 4889 | + expected := map[string]string{"happy": "case"} |
| 4890 | + result := parseTagsFromStr("happy:case") |
| 4891 | + if !reflect.DeepEqual(result, expected) { |
| 4892 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4893 | + } |
| 4894 | + }, |
| 4895 | + }, |
| 4896 | + { |
| 4897 | + name: "Success: simple multiple tags", |
| 4898 | + testFunc: func(t *testing.T) { |
| 4899 | + expected := map[string]string{"firstkey": "firstvalue", "secondkey": "secondvalue"} |
| 4900 | + result := parseTagsFromStr("firstkey:firstvalue secondkey:secondvalue") |
| 4901 | + if !reflect.DeepEqual(result, expected) { |
| 4902 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4903 | + } |
| 4904 | + }, |
| 4905 | + }, |
| 4906 | + { |
| 4907 | + name: "Success: complex key escaping", |
| 4908 | + testFunc: func(t *testing.T) { |
| 4909 | + expected := map[string]string{"first:key": "first value", "second key": "second:value"} |
| 4910 | + result := parseTagsFromStr("first\\:key:first\\ value second\\ key:second\\:value") |
| 4911 | + if !reflect.DeepEqual(result, expected) { |
| 4912 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4913 | + } |
| 4914 | + }, |
| 4915 | + }, |
| 4916 | + { |
| 4917 | + name: "Success: complex key escaping maintain backslash", |
| 4918 | + testFunc: func(t *testing.T) { |
| 4919 | + expected := map[string]string{"first:key": "first\\value", "second key": "second:value"} |
| 4920 | + result := parseTagsFromStr("first\\:key:first\\\\value second\\ key:second\\:value") |
| 4921 | + if !reflect.DeepEqual(result, expected) { |
| 4922 | + t.Fatalf("Incorrect tags: %v vs. %v", result, expected) |
| 4923 | + } |
| 4924 | + }, |
| 4925 | + }, |
| 4926 | + } |
| 4927 | + for _, tc := range testCases { |
| 4928 | + t.Run(tc.name, tc.testFunc) |
| 4929 | + } |
| 4930 | +} |
| 4931 | + |
4847 | 4932 | // Helper function to create mock client that returns error |
4848 | 4933 | func createMockClientWithError(errorMsg string) kubernetes.Interface { |
4849 | 4934 | return fake.NewSimpleClientset() |
|
0 commit comments