replaceAll replaces all instances of old with new in s, as well as all instances of the JSON-escaped version of old with the JSON-escaped version of new. This is because when the test is run on Windows the paths will have backslashes escaped in JSON and a simple strings.ReplaceAll won't catch them.
(s string, old string, new string)
| 1148 | // This is because when the test is run on Windows the paths will have backslashes |
| 1149 | // escaped in JSON and a simple strings.ReplaceAll won't catch them. |
| 1150 | func replaceAll(s string, old string, new string) string { |
| 1151 | jsonEscapedOld, _ := json.Marshal(old) |
| 1152 | jsonEscapedOld = jsonEscapedOld[1 : len(jsonEscapedOld)-1] |
| 1153 | |
| 1154 | jsonEscapedNew, _ := json.Marshal(new) |
| 1155 | jsonEscapedNew = jsonEscapedNew[1 : len(jsonEscapedNew)-1] |
| 1156 | |
| 1157 | replaced := strings.ReplaceAll(s, string(jsonEscapedOld), string(jsonEscapedNew)) |
| 1158 | replaced = strings.ReplaceAll(replaced, old, new) |
| 1159 | return replaced |
| 1160 | } |
| 1161 | |
| 1162 | func TestMaskToken(t *testing.T) { |
| 1163 | tests := []struct { |