Skip to content

Commit 60cf8f2

Browse files
committed
Convert tests to Kotlin
1 parent e8905ed commit 60cf8f2

15 files changed

+680
-688
lines changed

src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
204204
* @throws [MissingArgumentException, IllegalArgumentException]
205205
*/
206206
@JvmStatic
207-
fun getMatchingAgent(parameters: Map<String, String>, workspace: Workspace): WorkspaceAgentModel {
207+
fun getMatchingAgent(parameters: Map<String, String?>, workspace: Workspace): WorkspaceAgentModel {
208208
// A WorkspaceAgentModel will still be returned if there are no
209209
// agents; in this case it represents the workspace instead.
210210
// TODO: Seems confusing for something with "agent" in the name to

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fun ensureCLI(
9595
/**
9696
* Manage the CLI for a single deployment.
9797
*/
98-
class CoderCLIManager @JvmOverloads constructor(
98+
class CoderCLIManager(
9999
// The URL of the deployment this CLI is for.
100100
private val deploymentURL: URL,
101101
// Plugin configuration.

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

+25-15
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import com.coder.gateway.sdk.v2.models.Template
1212
import com.coder.gateway.sdk.v2.models.User
1313
import com.coder.gateway.sdk.v2.models.Workspace
1414
import com.coder.gateway.sdk.v2.models.WorkspaceBuild
15+
import com.coder.gateway.sdk.v2.models.WorkspaceResource
1516
import com.coder.gateway.sdk.v2.models.WorkspaceTransition
1617
import com.coder.gateway.sdk.v2.models.toAgentModels
1718
import com.coder.gateway.services.CoderSettings
1819
import com.coder.gateway.services.CoderSettingsService
20+
import com.coder.gateway.services.CoderSettingsState
1921
import com.coder.gateway.util.CoderHostnameVerifier
2022
import com.coder.gateway.util.coderSocketFactory
2123
import com.coder.gateway.util.coderTrustManagers
@@ -79,18 +81,18 @@ data class ProxyValues (
7981
* settings. Exists only so we can use the base client in tests.
8082
*/
8183
class DefaultCoderRestClient(url: URL, token: String) : CoderRestClient(url, token,
82-
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version,
8384
service<CoderSettingsService>(),
8485
ProxyValues(HttpConfigurable.getInstance().proxyLogin,
8586
HttpConfigurable.getInstance().plainProxyPassword,
8687
HttpConfigurable.getInstance().PROXY_AUTHENTICATION,
87-
HttpConfigurable.getInstance().onlyBySettingsSelector))
88+
HttpConfigurable.getInstance().onlyBySettingsSelector),
89+
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version)
8890

89-
open class CoderRestClient @JvmOverloads constructor(
91+
open class CoderRestClient(
9092
var url: URL, var token: String,
91-
private val pluginVersion: String,
92-
private val settings: CoderSettings,
93+
private val settings: CoderSettings = CoderSettings(CoderSettingsState()),
9394
private val proxyValues: ProxyValues? = null,
95+
private val pluginVersion: String = "development",
9496
) {
9597
private val httpClient: OkHttpClient
9698
private val retroRestClient: CoderV2RestFacade
@@ -166,20 +168,28 @@ open class CoderRestClient @JvmOverloads constructor(
166168
}
167169

168170
/**
169-
* Retrieves agents for the specified workspaces. Since the workspaces
170-
* response does not include agents when the workspace is off, this fires
171-
* off separate queries to get the agents for each workspace, just like
172-
* `coder config-ssh` does (otherwise we risk removing hosts from the SSH
173-
* config when they are off).
171+
* Retrieves agents for the specified workspaces, including those that are
172+
* off.
174173
*/
175174
fun agents(workspaces: List<Workspace>): List<WorkspaceAgentModel> {
176175
return workspaces.flatMap {
177-
val resourcesResponse = retroRestClient.templateVersionResources(it.latestBuild.templateVersionID).execute()
178-
if (!resourcesResponse.isSuccessful) {
179-
throw WorkspaceResponseException("Unable to retrieve template resources for ${it.name} from $url: code ${resourcesResponse.code()}, reason: ${resourcesResponse.message().ifBlank { "no reason provided" }}")
180-
}
181-
it.toAgentModels(resourcesResponse.body()!!)
176+
val resources = resources(it)
177+
it.toAgentModels(resources)
178+
}
179+
}
180+
181+
/**
182+
* Retrieves resources for the specified workspace. The workspaces response
183+
* does not include agents when the workspace is off so this can be used to
184+
* get them instead, just like `coder config-ssh` does (otherwise we risk
185+
* removing hosts from the SSH config when they are off).
186+
*/
187+
fun resources(workspace: Workspace): List<WorkspaceResource> {
188+
val resourcesResponse = retroRestClient.templateVersionResources(workspace.latestBuild.templateVersionID).execute()
189+
if (!resourcesResponse.isSuccessful) {
190+
throw WorkspaceResponseException("Unable to retrieve template resources for ${workspace.name} from $url: code ${resourcesResponse.code()}, reason: ${resourcesResponse.message().ifBlank { "no reason provided" }}")
182191
}
192+
return resourcesResponse.body()!!
183193
}
184194

185195
fun buildInfo(): BuildInfo {

src/main/kotlin/com/coder/gateway/services/CoderSettingsState.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Environment(private val env: Map<String, String> = emptyMap()) {
116116
* some extra convenience wrappers while letting the settings page still read
117117
* and mutate the underlying state.
118118
*/
119-
open class CoderSettings @JvmOverloads constructor(
119+
open class CoderSettings(
120120
private val state: CoderSettingsState,
121121
// The location of the SSH config. Defaults to ~/.ssh/config.
122122
val sshConfigPath: Path = Path.of(System.getProperty("user.home")).resolve(".ssh/config"),

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ class WorkspacesTable : TableView<WorkspaceAgentModel>(WorkspacesTableModel()) {
797797
}
798798
}
799799

800-
private fun getNewSelection(oldSelection: WorkspaceAgentModel?): Int {
800+
fun getNewSelection(oldSelection: WorkspaceAgentModel?): Int {
801801
if (oldSelection == null) {
802802
return -1
803803
}

src/test/groovy/CoderGatewayConnectionProviderTest.groovy

-114
This file was deleted.

src/test/groovy/CoderRemoteConnectionHandleTest.groovy

-72
This file was deleted.

0 commit comments

Comments
 (0)