| 1 |
package filesystems |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestParseProperties(t *testing.T) { |
| 9 |
testData := []struct { |
| 10 |
name string |
| 11 |
input string |
| 12 |
expected map[string]string |
| 13 |
expectError bool |
| 14 |
}{ |
| 15 |
{ |
| 16 |
name: "no items", |
| 17 |
input: "", |
| 18 |
expected: map[string]string{}, |
| 19 |
expectError: false, |
| 20 |
}, |
| 21 |
{ |
| 22 |
name: "invalid item", |
| 23 |
input: "hello", |
| 24 |
expectError: true, |
| 25 |
}, |
| 26 |
{ |
| 27 |
name: "single item", |
| 28 |
input: "hello=world", |
| 29 |
expected: map[string]string{ |
| 30 |
"hello": "world", |
| 31 |
}, |
| 32 |
}, |
| 33 |
{ |
| 34 |
name: "single-item-base64", |
| 35 |
input: "hello=aGVsbG8=", |
| 36 |
expected: map[string]string{ |
| 37 |
"hello": "aGVsbG8=", |
| 38 |
}, |
| 39 |
expectError: false, |
| 40 |
}, |
| 41 |
{ |
| 42 |
name: "single-item-base64-multipleequals", |
| 43 |
input: "hello=d29uZGVybGFuZA==", |
| 44 |
expected: map[string]string{ |
| 45 |
"hello": "d29uZGVybGFuZA==", |
| 46 |
}, |
| 47 |
expectError: false, |
| 48 |
}, |
| 49 |
{ |
| 50 |
name: "multiple-items-base64", |
| 51 |
input: "hello=d29uZGVybGFuZA==,private=ZXll", |
| 52 |
|
| 53 |
expected: map[string]string{ |
| 54 |
"hello": "d29uZGVybGFuZA==", |
| 55 |
"private": "ZXll", |
| 56 |
}, |
| 57 |
expectError: false, |
| 58 |
}, |
| 59 |
} |
| 60 |
|
| 61 |
for _, testCase := range testData { |
| 62 |
t.Logf("[DEBUG] Test %q", testCase.name) |
| 63 |
|
| 64 |
actual, err := parseProperties(testCase.input) |
| 65 |
if err != nil { |
| 66 |
if testCase.expectError { |
| 67 |
continue |
| 68 |
} |
| 69 |
|
| 70 |
t.Fatalf("[DEBUG] Didn't expect an error but got %s", err) |
| 71 |
} |
| 72 |
if !reflect.DeepEqual(testCase.expected, *actual) { |
| 73 |
t.Fatalf("Expected %+v but got %+v", testCase.expected, *actual) |
| 74 |
} |
| 75 |
} |
| 76 |
} |