Skip to content

Commit a605d79

Browse files
committed
Use golden files for SSH config tests
Also add trailing newline when appending to file. Just a bit nicer, for example when you cat the file. If we are replacing a block at the end and there is no newline then we will preserve that; no newlines are added when replacing.
1 parent 17c0edf commit a605d79

29 files changed

+299
-367
lines changed

src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,11 @@ class CoderCLIManager @JvmOverloads constructor(private val deploymentURL: URL,
196196
logger.info("Leaving $sshConfigPath alone since there are no workspaces and no config to remove")
197197
} else if (start == null && end == null) {
198198
logger.info("Appending config to $sshConfigPath")
199-
sshConfigPath.toFile().writeText(
200-
if (contents.isEmpty()) blockContent else listOf(
201-
contents,
202-
blockContent
203-
).joinToString(System.lineSeparator())
204-
)
199+
val toAppend = if (contents.isEmpty()) blockContent else listOf(
200+
contents,
201+
blockContent
202+
).joinToString(System.lineSeparator())
203+
sshConfigPath.toFile().writeText(toAppend + System.lineSeparator())
205204
} else if (start == null) {
206205
throw SSHConfigFormatException("End block exists but no start block")
207206
} else if (end == null) {
@@ -234,7 +233,7 @@ class CoderCLIManager @JvmOverloads constructor(private val deploymentURL: URL,
234233
}
235234
} catch (e: FileNotFoundException) {
236235
logger.info("Writing config to $sshConfigPath")
237-
sshConfigPath.toFile().writeText(blockContent)
236+
sshConfigPath.toFile().writeText(blockContent + System.lineSeparator())
238237
}
239238
}
240239

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+

src/test/fixtures/inputs/blank.conf

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Host test
2+
Port 80
3+
Host test2
4+
Port 443 # --- START CODER JETBRAINS test.coder.invalid
5+
some jetbrains config # --- END CODER JETBRAINS test.coder.invalid
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Host test
2+
Port 80
3+
Host test2
4+
Port 443
5+
# --- START CODER JETBRAINS test.coder.invalid
6+
some jetbrains config
7+
# --- END CODER JETBRAINS test.coder.invalid
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Host test
2+
Port 80
3+
# ------------START-CODER-----------
4+
some coder config
5+
# ------------END-CODER------------
6+
# --- START CODER JETBRAINS test.coder.invalid
7+
some jetbrains config
8+
# --- END CODER JETBRAINS test.coder.invalid
9+
Host test2
10+
Port 443
11+
# --- START CODER JETBRAINS test.coder.unrelated
12+
some jetbrains config
13+
# --- END CODER JETBRAINS test.coder.unrelated
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Host test
2+
Port 80
3+
# --- START CODER JETBRAINS test.coder.invalid
4+
some jetbrains config
5+
# --- END CODER JETBRAINS test.coder.invalid
6+
Host test2
7+
Port 443
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# --- START CODER JETBRAINS test.coder.invalid
2+
some jetbrains config
3+
# --- END CODER JETBRAINS test.coder.invalid
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --- START CODER JETBRAINS test.coder.invalid
2+
some jetbrains config
3+
# --- END CODER JETBRAINS test.coder.invalid
4+
Host test
5+
Port 80
6+
Host test2
7+
Port 443
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# --- START CODER JETBRAINS test.coder.something-else
2+
some jetbrains config
3+
# --- END CODER JETBRAINS test.coder.invalid

0 commit comments

Comments
 (0)