-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[none] configuring tag+push feature of tagger into a test spec in ant…
…icipation of adding it to cli
- Loading branch information
1 parent
7bb373c
commit ad22409
Showing
5 changed files
with
133 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
package com.zegreatrob.tools.tagger | ||
|
||
import com.zegreatrob.tools.adapter.git.GitAdapter | ||
import com.zegreatrob.tools.adapter.git.runProcess | ||
import org.ajoberstar.grgit.Grgit | ||
import org.ajoberstar.grgit.operation.CommitOp | ||
import org.ajoberstar.grgit.operation.InitOp | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.jupiter.api.io.TempDir | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.createTempDirectory | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CalculateVersionFunctionalTest : CalculateVersionTestSpec { | ||
@field:TempDir | ||
|
@@ -44,7 +34,7 @@ class CalculateVersionFunctionalTest : CalculateVersionTestSpec { | |
) | ||
} | ||
|
||
override fun setupWithOverrides( | ||
override fun configureWithOverrides( | ||
implicitPatch: Boolean?, | ||
majorRegex: String?, | ||
minorRegex: String?, | ||
|
@@ -81,39 +71,7 @@ class CalculateVersionFunctionalTest : CalculateVersionTestSpec { | |
) | ||
} | ||
|
||
@Test | ||
fun tagWillTagAndPushSuccessfully() { | ||
setupWithDefaults() | ||
|
||
val originDirectory = createTempDirectory() | ||
val originGrgit = Grgit.init(fun InitOp.() { | ||
this.dir = originDirectory.absolutePathString() | ||
}) | ||
disableGpgSign(originDirectory.toFile()) | ||
originGrgit.commit(fun CommitOp.() { | ||
this.message = "init" | ||
}) | ||
val grgit = initializeGitRepo( | ||
listOf("init", "[patch] commit 1", "[patch] commit 2"), | ||
remoteUrl = originDirectory.absolutePathString(), | ||
) | ||
grgit.push() | ||
|
||
runProcess(listOf("git", "config", "user.email", "[email protected]"), this.projectDir.absolutePath) | ||
runProcess(listOf("git", "config", "user.name", "RoB as Test"), this.projectDir.absolutePath) | ||
|
||
val runner = GradleRunner.create() | ||
runner.forwardOutput() | ||
runner.withPluginClasspath() | ||
runner.withArguments("tag", "-Pversion=1.0.0") | ||
runner.withProjectDir(projectDir) | ||
runner.build() | ||
|
||
val gitAdapter = GitAdapter(this.projectDir.absolutePath) | ||
assertEquals("1.0.0", gitAdapter.showTag("HEAD")) | ||
} | ||
|
||
override fun runCalculateVersion(): TestResult { | ||
override fun execute(): TestResult { | ||
val runner = GradleRunner.create() | ||
runner.forwardOutput() | ||
runner.withPluginClasspath() | ||
|
@@ -126,11 +84,4 @@ class CalculateVersionFunctionalTest : CalculateVersionTestSpec { | |
TestResult.Failure(e.message!!) | ||
} | ||
} | ||
|
||
private fun disableGpgSign(directory: File) { | ||
FileOutputStream(directory.resolve(".git/config"), true) | ||
.writer().use { | ||
it.write("[commit]\n gpgsign = false") | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/tagger/TagAndPushFunctionalTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.zegreatrob.tools.tagger | ||
|
||
import com.zegreatrob.tools.adapter.git.runProcess | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.jupiter.api.io.TempDir | ||
import java.io.File | ||
import kotlin.test.BeforeTest | ||
|
||
class TagAndPushFunctionalTest : TagAndPushTestSpec { | ||
|
||
@field:TempDir | ||
override lateinit var projectDir: File | ||
|
||
private val buildFile by lazy { projectDir.resolve("build.gradle.kts") } | ||
private val settingsFile by lazy { projectDir.resolve("settings.gradle") } | ||
private val ignoreFile by lazy { projectDir.resolve(".gitignore") } | ||
override val addFileNames: Set<String> | ||
get() = setOf(buildFile, settingsFile, ignoreFile).map { it.name }.toSet() | ||
|
||
@BeforeTest | ||
fun setup() { | ||
settingsFile.writeText("") | ||
ignoreFile.writeText(".gradle") | ||
} | ||
|
||
override fun configureWithDefaults() { | ||
buildFile.writeText( | ||
""" | ||
plugins { | ||
id("com.zegreatrob.tools.tagger") | ||
} | ||
tagger { | ||
releaseBranch = "master" | ||
} | ||
""".trimIndent(), | ||
) | ||
} | ||
|
||
override fun execute(): TestResult { | ||
runProcess(listOf("git", "config", "user.email", "[email protected]"), this.projectDir.absolutePath) | ||
runProcess(listOf("git", "config", "user.name", "RoB as Test"), this.projectDir.absolutePath) | ||
|
||
val runner = GradleRunner.create() | ||
runner.forwardOutput() | ||
runner.withPluginClasspath() | ||
runner.withArguments("tag", "-Pversion=1.0.0") | ||
runner.withProjectDir(projectDir) | ||
return try { | ||
val result = runner.build() | ||
result.output.trim().let(TestResult::Success) | ||
} catch (e: Exception) { | ||
TestResult.Failure(e.message!!) | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...tagger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/tagger/TagAndPushTestSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.zegreatrob.tools.tagger | ||
|
||
import com.zegreatrob.tools.adapter.git.GitAdapter | ||
import com.zegreatrob.tools.test.git.disableGpgSign | ||
import org.ajoberstar.grgit.Grgit | ||
import org.ajoberstar.grgit.operation.CommitOp | ||
import org.ajoberstar.grgit.operation.InitOp | ||
import java.io.File | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.createTempDirectory | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
interface TagAndPushTestSpec { | ||
var projectDir: File | ||
val addFileNames: Set<String> | ||
|
||
fun initializeGitRepo( | ||
commits: List<String>, | ||
initialTag: String? = null, | ||
remoteUrl: String = projectDir.absolutePath, | ||
) = com.zegreatrob.tools.test.git.initializeGitRepo( | ||
directory = projectDir.absolutePath, | ||
remoteUrl = remoteUrl, | ||
addFileNames = addFileNames, | ||
initialTag = initialTag, | ||
commits = commits, | ||
) | ||
|
||
fun configureWithDefaults() | ||
fun execute(): TestResult | ||
|
||
@Test | ||
fun tagWillTagAndPushSuccessfully() { | ||
configureWithDefaults() | ||
|
||
val originDirectory = createTempDirectory() | ||
val originGrgit = Grgit.init(fun InitOp.() { | ||
this.dir = originDirectory.absolutePathString() | ||
}) | ||
disableGpgSign(originDirectory.absolutePathString()) | ||
originGrgit.commit(fun CommitOp.() { | ||
this.message = "init" | ||
}) | ||
val grgit = initializeGitRepo( | ||
listOf("init", "[patch] commit 1", "[patch] commit 2"), | ||
remoteUrl = originDirectory.absolutePathString(), | ||
) | ||
grgit.push() | ||
|
||
execute() | ||
|
||
val gitAdapter = GitAdapter(this.projectDir.absolutePath) | ||
assertEquals("1.0.0", gitAdapter.showTag("HEAD")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters