Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve self-test CLI to auto-remove host trailing slash #77

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ object DatabricksConfigParser {
configurationProfileName: String,
sysEnv: Map[String, String]
): (Option[String], Option[String]) = {
if (useEnvVariables) {
getConfigFromEnvVariables(sysEnv)
} else {
getDatabricksConfigFromProfile(configurationProfileName, sysEnv)
}
val (host, token) = if (useEnvVariables) getConfigFromEnvVariables(sysEnv) else getDatabricksConfigFromProfile(configurationProfileName, sysEnv)
return (host.map(_.stripSuffix("/")), token)
}

/** Finds the value for a field in a line from a Databricks configuration
Expand Down
4 changes: 4 additions & 0 deletions self-testing-partner-cli/src/test/resources/.testcfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[DEFAULT]
host = defaulthost
token = defaulttoken

[TRAILING_SLASH]
host = https://anotherhost.com/
token = defaulttoken
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.scalatest.funsuite.AnyFunSuite

class DatabricksConfigParserSuite extends AnyFunSuite {
private val testHost = "defaulthost"
private val trailingSlashRemovedHost = "https://anotherhost.com"
private val testToken = "defaulttoken"

test("PROFILE - Successfully gets host/token from profile") {
Expand Down Expand Up @@ -46,6 +47,20 @@ class DatabricksConfigParserSuite extends AnyFunSuite {
stream.close()
}

test("PROFILE - Successfully remove host trailing slash from profile") {
val profileName = "TRAILING_SLASH"
val stream = new java.io.ByteArrayOutputStream()
val env =
Map(configFilePathEnvVariable -> getClass.getResource(".testcfg").getPath)
val (host, token) = Console.withErr(stream) {
getHostAndToken(useEnvVariables = false, profileName, env)
}
assert(stream.toString.isEmpty)
assert(host.get == trailingSlashRemovedHost)
assert(token.get == testToken)
stream.close()
}

test(
"ENVIRONMENT VARIABLES - Successfully gets host/token from env variables"
) {
Expand Down Expand Up @@ -87,4 +102,16 @@ class DatabricksConfigParserSuite extends AnyFunSuite {
)
stream.close()
}

test("ENVIRONMENT VARIABLES - Successfully remove host trailing slash") {
val env = Map(hostEnvVariable -> s"$trailingSlashRemovedHost/", tokenEnvVariable -> testToken)
val stream = new java.io.ByteArrayOutputStream()
val (host, token) = Console.withOut(stream) {
getHostAndToken(useEnvVariables = true, "default", env)
}
assert(stream.toString.isEmpty)
assert(host.get == trailingSlashRemovedHost)
assert(token.get == testToken)
stream.close()
}
}
Loading