add bootstrapping.md
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package de.hoennig.gittally.commands
|
||||
|
||||
import de.hoennig.gittally.git.GitService
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.file.shouldExist
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
class InitCommandTest : FunSpec() {
|
||||
private val gitService = mockk<GitService>()
|
||||
private val initCommand = InitCommand(gitService)
|
||||
|
||||
init {
|
||||
test("creates config files with auto-detected values") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
|
||||
every { gitService.getTopLevel(tempDir) } returns tempDir
|
||||
every { gitService.getOriginUrl(tempDir) } returns "https://git.example.org/my-org/my-repo.git"
|
||||
|
||||
initCommand.run()
|
||||
|
||||
val projectConfig = tempDir.resolve(".gittally.yml")
|
||||
projectConfig.toFile().shouldExist()
|
||||
val projectContent = projectConfig.toFile().readText()
|
||||
projectContent shouldContain "baseUrl: https://git.example.org"
|
||||
projectContent shouldContain "owner: my-org"
|
||||
projectContent shouldContain "repo: my-repo"
|
||||
|
||||
val repoConfig = tempDir.resolve(".git/gittally/.gittally.yml")
|
||||
repoConfig.toFile().shouldExist()
|
||||
val repoContent = repoConfig.toFile().readText()
|
||||
repoContent shouldContain "account: \"\"" // no user in https URL
|
||||
}
|
||||
|
||||
test("detects account from https url") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
|
||||
every { gitService.getTopLevel(tempDir) } returns tempDir
|
||||
every { gitService.getOriginUrl(tempDir) } returns "https://ci-user@git.example.org/my-org/my-repo.git"
|
||||
|
||||
initCommand.run()
|
||||
|
||||
val repoConfig = tempDir.resolve(".git/gittally/.gittally.yml")
|
||||
val repoContent = repoConfig.toFile().readText()
|
||||
repoContent shouldContain "account: \"ci-user\""
|
||||
}
|
||||
|
||||
test("parses ssh url") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
|
||||
every { gitService.getTopLevel(tempDir) } returns tempDir
|
||||
every { gitService.getOriginUrl(tempDir) } returns "git@git.example.org:my-org/my-repo.git"
|
||||
|
||||
initCommand.run()
|
||||
|
||||
val projectConfig = tempDir.resolve(".gittally.yml")
|
||||
val projectContent = projectConfig.toFile().readText()
|
||||
projectContent shouldContain "baseUrl: https://git.example.org" // fallback to https
|
||||
projectContent shouldContain "owner: my-org"
|
||||
projectContent shouldContain "repo: my-repo"
|
||||
}
|
||||
|
||||
test("does not overwrite existing files") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
|
||||
val projectConfig = tempDir.resolve(".gittally.yml")
|
||||
projectConfig.toFile().writeText("existing: content")
|
||||
|
||||
every { gitService.getTopLevel(tempDir) } returns tempDir
|
||||
every { gitService.getOriginUrl(tempDir) } returns "https://git.example.org/my-org/my-repo.git"
|
||||
|
||||
initCommand.run()
|
||||
|
||||
projectConfig.toFile().readText() shouldBe "existing: content"
|
||||
}
|
||||
|
||||
test("reproduces path root mismatch issue") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test").toAbsolutePath().normalize()
|
||||
initCommand.workingDir = Paths.get(".") // Set to relative path as in real app
|
||||
|
||||
// We need to mock getTopLevel to return the absolute path
|
||||
every { gitService.getTopLevel(any()) } returns tempDir
|
||||
every { gitService.getOriginUrl(any()) } returns "https://git.example.org/my-org/my-repo.git"
|
||||
|
||||
// This should not throw IllegalArgumentException
|
||||
initCommand.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ class ConfigLoaderTest : FunSpec() {
|
||||
val config = loader.load(dir)
|
||||
config.gitea.owner shouldBe "my-org"
|
||||
config.gitea.repo shouldBe "my-repo"
|
||||
config.branches["default"]!!.buildCommand shouldBe BranchConfig().buildCommand
|
||||
}
|
||||
|
||||
test("repo install config overrides project config for same keys") {
|
||||
@@ -40,20 +39,23 @@ class ConfigLoaderTest : FunSpec() {
|
||||
dir.resolve(".gittally.yml").toFile().writeText(
|
||||
"""
|
||||
gitea:
|
||||
owner: my-org
|
||||
owner: original-org
|
||||
git:
|
||||
token: from-project
|
||||
""".trimIndent(),
|
||||
)
|
||||
dir.resolve(".git/gittally").toFile().mkdirs()
|
||||
dir.resolve(".git/gittally/config.yml").toFile().writeText(
|
||||
dir.resolve(".git/gittally/.gittally.yml").toFile().writeText(
|
||||
"""
|
||||
gitea:
|
||||
owner: override-org
|
||||
git:
|
||||
token: from-repo-install
|
||||
""".trimIndent(),
|
||||
)
|
||||
val config = loader.load(dir)
|
||||
config.gitea.owner shouldBe "my-org"
|
||||
config.gitea.token shouldBe "from-repo-install"
|
||||
config.gitea.owner shouldBe "override-org"
|
||||
config.git.token shouldBe "from-repo-install"
|
||||
}
|
||||
|
||||
test("loadRaw only returns explicitly set values") {
|
||||
@@ -108,6 +110,7 @@ class ConfigLoaderTest : FunSpec() {
|
||||
test("toYaml serializes GitTallyConfig with all sections") {
|
||||
val yaml = loader.toYaml(GitTallyConfig())
|
||||
yaml shouldContain "server:"
|
||||
yaml shouldContain "git:"
|
||||
yaml shouldContain "gitea:"
|
||||
yaml shouldContain "artifacts:"
|
||||
yaml shouldContain "watcher:"
|
||||
|
||||
Reference in New Issue
Block a user