Skip to content

Commit b58e8fe

Browse files
committed
more windows fix
1 parent d38c0a6 commit b58e8fe

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/WorkspaceFolderUtilTest.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class WorkspaceFolderUtilTest {
7070
every { toUri() } returns uri
7171
}
7272
return mockk<VirtualFile> {
73-
every { url } returns uri.toString()
73+
every { url } returns normalizeFileUri(uri.toString())
7474
every { getName() } returns name
7575
every { toNioPath() } returns path
7676
every { isDirectory } returns false
@@ -79,4 +79,18 @@ class WorkspaceFolderUtilTest {
7979
}
8080
}
8181
}
82+
83+
// for windows unit tests
84+
private fun normalizeFileUri(uri: String): String {
85+
if (!System.getProperty("os.name").lowercase().contains("windows")) {
86+
return uri
87+
}
88+
89+
if (!uri.startsWith("file:///")) {
90+
return uri
91+
}
92+
93+
val path = uri.substringAfter("file:///")
94+
return "file:///C:/$path"
95+
}
8296
}

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandlerTest.kt

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class WorkspaceServiceHandlerTest {
106106

107107
val paramsSlot = slot<CreateFilesParams>()
108108
verify { mockWorkspaceService.didCreateFiles(capture(paramsSlot)) }
109-
assertEquals(pyUri.toString(), paramsSlot.captured.files[0].uri)
109+
assertEquals(normalizeFileUri(pyUri.toString()), paramsSlot.captured.files[0].uri)
110110
}
111111

112112
@Test
@@ -118,7 +118,7 @@ class WorkspaceServiceHandlerTest {
118118

119119
val paramsSlot = slot<CreateFilesParams>()
120120
verify { mockWorkspaceService.didCreateFiles(capture(paramsSlot)) }
121-
assertEquals(tsUri.toString(), paramsSlot.captured.files[0].uri)
121+
assertEquals(normalizeFileUri(tsUri.toString()), paramsSlot.captured.files[0].uri)
122122
}
123123

124124
@Test
@@ -130,7 +130,7 @@ class WorkspaceServiceHandlerTest {
130130

131131
val paramsSlot = slot<CreateFilesParams>()
132132
verify { mockWorkspaceService.didCreateFiles(capture(paramsSlot)) }
133-
assertEquals(jsUri.toString(), paramsSlot.captured.files[0].uri)
133+
assertEquals(normalizeFileUri(jsUri.toString()), paramsSlot.captured.files[0].uri)
134134
}
135135

136136
@Test
@@ -142,7 +142,7 @@ class WorkspaceServiceHandlerTest {
142142

143143
val paramsSlot = slot<CreateFilesParams>()
144144
verify { mockWorkspaceService.didCreateFiles(capture(paramsSlot)) }
145-
assertEquals(javaUri.toString(), paramsSlot.captured.files[0].uri)
145+
assertEquals(normalizeFileUri(javaUri.toString()), paramsSlot.captured.files[0].uri)
146146
}
147147

148148
@Test
@@ -154,7 +154,7 @@ class WorkspaceServiceHandlerTest {
154154

155155
val paramsSlot = slot<CreateFilesParams>()
156156
verify { mockWorkspaceService.didCreateFiles(capture(paramsSlot)) }
157-
assertEquals(dirUri.toString(), paramsSlot.captured.files[0].uri)
157+
assertEquals(normalizeFileUri(dirUri.toString()), paramsSlot.captured.files[0].uri)
158158
}
159159

160160
@Test
@@ -176,7 +176,7 @@ class WorkspaceServiceHandlerTest {
176176

177177
val paramsSlot = slot<DeleteFilesParams>()
178178
verify { mockWorkspaceService.didDeleteFiles(capture(paramsSlot)) }
179-
assertEquals(pyUri.toString(), paramsSlot.captured.files[0].uri)
179+
assertEquals(normalizeFileUri(pyUri.toString()), paramsSlot.captured.files[0].uri)
180180
}
181181

182182
@Test
@@ -188,7 +188,7 @@ class WorkspaceServiceHandlerTest {
188188

189189
val paramsSlot = slot<DeleteFilesParams>()
190190
verify { mockWorkspaceService.didDeleteFiles(capture(paramsSlot)) }
191-
assertEquals(tsUri.toString(), paramsSlot.captured.files[0].uri)
191+
assertEquals(normalizeFileUri(tsUri.toString()), paramsSlot.captured.files[0].uri)
192192
}
193193

194194
@Test
@@ -200,7 +200,7 @@ class WorkspaceServiceHandlerTest {
200200

201201
val paramsSlot = slot<DeleteFilesParams>()
202202
verify { mockWorkspaceService.didDeleteFiles(capture(paramsSlot)) }
203-
assertEquals(jsUri.toString(), paramsSlot.captured.files[0].uri)
203+
assertEquals(normalizeFileUri(jsUri.toString()), paramsSlot.captured.files[0].uri)
204204
}
205205

206206
@Test
@@ -212,7 +212,7 @@ class WorkspaceServiceHandlerTest {
212212

213213
val paramsSlot = slot<DeleteFilesParams>()
214214
verify { mockWorkspaceService.didDeleteFiles(capture(paramsSlot)) }
215-
assertEquals(javaUri.toString(), paramsSlot.captured.files[0].uri)
215+
assertEquals(normalizeFileUri(javaUri.toString()), paramsSlot.captured.files[0].uri)
216216
}
217217

218218
@Test
@@ -234,7 +234,7 @@ class WorkspaceServiceHandlerTest {
234234

235235
val paramsSlot = slot<DeleteFilesParams>()
236236
verify { mockWorkspaceService.didDeleteFiles(capture(paramsSlot)) }
237-
assertEquals(dirUri.toString(), paramsSlot.captured.files[0].uri)
237+
assertEquals(normalizeFileUri(dirUri.toString()), paramsSlot.captured.files[0].uri)
238238
}
239239

240240
@Test
@@ -254,11 +254,11 @@ class WorkspaceServiceHandlerTest {
254254
// Assert
255255
val paramsSlot = slot<DidChangeWatchedFilesParams>()
256256
verify { mockWorkspaceService.didChangeWatchedFiles(capture(paramsSlot)) }
257-
assertEquals(createURI.toString(), paramsSlot.captured.changes[0].uri)
257+
assertEquals(normalizeFileUri(createURI.toString()), paramsSlot.captured.changes[0].uri)
258258
assertEquals(FileChangeType.Created, paramsSlot.captured.changes[0].type)
259-
assertEquals(deleteURI.toString(), paramsSlot.captured.changes[1].uri)
259+
assertEquals(normalizeFileUri(deleteURI.toString()), paramsSlot.captured.changes[1].uri)
260260
assertEquals(FileChangeType.Deleted, paramsSlot.captured.changes[1].type)
261-
assertEquals(changeURI.toString(), paramsSlot.captured.changes[2].uri)
261+
assertEquals(normalizeFileUri(changeURI.toString()), paramsSlot.captured.changes[2].uri)
262262
assertEquals(FileChangeType.Changed, paramsSlot.captured.changes[2].type)
263263
}
264264

@@ -566,4 +566,18 @@ class WorkspaceServiceHandlerTest {
566566
every { newValue } returns newName
567567
}
568568
}
569+
570+
// for windows unit tests
571+
private fun normalizeFileUri(uri: String): String {
572+
if (!System.getProperty("os.name").lowercase().contains("windows")) {
573+
return uri
574+
}
575+
576+
if (!uri.startsWith("file:///")) {
577+
return uri
578+
}
579+
580+
val path = uri.substringAfter("file:///")
581+
return "file:///C:/$path"
582+
}
569583
}

0 commit comments

Comments
 (0)