Skip to content

Commit

Permalink
improve remote origin parsing tests (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinSchramm authored May 27, 2023
1 parent 380f63b commit ba37f92
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class GitConfigPropertiesProvider(
return runCatching {
URI(this).userInfo?.let {
this.replace(it, "").replace("@", "")
}
}.getOrDefault(this)
} ?: this
}.getOrElse { null }

}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,68 @@ import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.StoredConfig

class GitConfigPropertiesProviderTest : StringSpec({

val storedConfig = mockk<StoredConfig>() {
every { load() } returns Unit
}
val git = mockk<Git>() {
every { repository.config } returns mockk(relaxed = true) {
every { getString("user", null, "email") } returns "[email protected]"
every { getString("user", null, "name") } returns "John Smith"
every { getString("remote", "origin", "url") } returns "https://name:[email protected]/hndrs/gradle-git-properties-plugin.git"
}
every { repository.config } returns storedConfig
}

val underTest = GitConfigPropertiesProvider(git)

"resolves git branch via git" {
"resolves git config properties (remote origin with credentials)" {

every { storedConfig.getString("user", null, "email") } returns "[email protected]"
every { storedConfig.getString("user", null, "name") } returns "John Smith"
every { storedConfig.getString("remote", "origin", "url") } returns "https://name:[email protected]/hndrs/gradle-git-properties-plugin.git"

underTest.get() shouldBe mapOf(
"git.build.user.email" to "[email protected]",
"git.build.user.name" to "John Smith",
"git.remote.origin.url" to "https://github.com/hndrs/gradle-git-properties-plugin.git"
)
}

"resolves git config properties (remote with git/ssh )" {

every { storedConfig.getString("user", null, "email") } returns "[email protected]"
every { storedConfig.getString("user", null, "name") } returns "John Smith"
every { storedConfig.getString("remote", "origin", "url") } returns "[email protected]/hndrs/gradle-git-properties-plugin.git"

underTest.get() shouldBe mapOf(
"git.build.user.email" to "[email protected]",
"git.build.user.name" to "John Smith",
"git.remote.origin.url" to "[email protected]/hndrs/gradle-git-properties-plugin.git"
)
}

"resolves git config properties (with unrecognized data)" {

every { storedConfig.getString("user", null, "email") } returns "[email protected]"
every { storedConfig.getString("user", null, "name") } returns "John Smith"
every { storedConfig.getString("remote", "origin", "url") } returns "someUnrelatedString"

underTest.get() shouldBe mapOf(
"git.build.user.email" to "[email protected]",
"git.build.user.name" to "John Smith",
"git.remote.origin.url" to "someUnrelatedString"
)
}

"resolves git config properties (with exception on parsing data)" {

every { storedConfig.getString("user", null, "email") } returns "[email protected]"
every { storedConfig.getString("user", null, "name") } returns "John Smith"
every { storedConfig.getString("remote", "origin", "url") } returns "https>"

underTest.get() shouldBe mapOf(
"git.build.user.email" to "[email protected]",
"git.build.user.name" to "John Smith",
"git.remote.origin.url" to null
)
}
})

0 comments on commit ba37f92

Please sign in to comment.