-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from mattprecious/mattp/2025-02-24/branch-cre…
…ate-test Add BranchCreateTest
- Loading branch information
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
src/commonTest/kotlin/com/mattprecious/stacker/test/command/BranchCreateTest.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,111 @@ | ||
package com.mattprecious.stacker.test.command | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.containsExactly | ||
import assertk.assertions.containsExactlyInAnyOrder | ||
import assertk.assertions.isFalse | ||
import assertk.assertions.isTrue | ||
import com.mattprecious.stacker.command.branch.branchCreate | ||
import com.mattprecious.stacker.command.repo.repoInit | ||
import com.mattprecious.stacker.db.Branch | ||
import com.mattprecious.stacker.delegates.Optional | ||
import com.mattprecious.stacker.test.util.gitCommit | ||
import com.mattprecious.stacker.test.util.gitCreateAndCheckoutBranch | ||
import com.mattprecious.stacker.test.util.gitInit | ||
import com.mattprecious.stacker.test.util.withTestEnvironment | ||
import kotlin.test.Test | ||
|
||
class BranchCreateTest { | ||
@Test | ||
fun branchFromTrunk() = withTestEnvironment { | ||
gitInit() | ||
val mainSha = gitCommit("Empty") | ||
testCommand({ repoInit("main", Optional.None) }) | ||
|
||
testCommand({ branchCreate("change-a") }) { | ||
awaitFrame("") | ||
assertThat(awaitResult()).isTrue() | ||
} | ||
|
||
withDatabase { | ||
assertThat(it.branchQueries.selectAll().executeAsList()).containsExactlyInAnyOrder( | ||
Branch( | ||
name = "main", | ||
parent = null, | ||
parentSha = null, | ||
prNumber = null, | ||
hasAskedToDelete = false, | ||
), | ||
Branch( | ||
name = "change-a", | ||
parent = "main", | ||
parentSha = mainSha.long, | ||
prNumber = null, | ||
hasAskedToDelete = false, | ||
), | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun branchFromNonTrunkBranch() = withTestEnvironment { | ||
gitInit() | ||
val mainSha = gitCommit("Empty") | ||
testCommand({ repoInit("main", Optional.None) }) | ||
testCommand({ branchCreate("change-a") }) | ||
val parentSha = gitCommit("Change A") | ||
|
||
testCommand({ branchCreate("change-b") }) { | ||
awaitFrame("") | ||
assertThat(awaitResult()).isTrue() | ||
} | ||
|
||
withDatabase { | ||
assertThat(it.branchQueries.selectAll().executeAsList()).containsExactlyInAnyOrder( | ||
Branch( | ||
name = "main", | ||
parent = null, | ||
parentSha = null, | ||
prNumber = null, | ||
hasAskedToDelete = false, | ||
), | ||
Branch( | ||
name = "change-a", | ||
parent = "main", | ||
parentSha = mainSha.long, | ||
prNumber = null, | ||
hasAskedToDelete = false, | ||
), | ||
Branch( | ||
name = "change-b", | ||
parent = "change-a", | ||
parentSha = parentSha.long, | ||
prNumber = null, | ||
hasAskedToDelete = false, | ||
), | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun branchFromUntrackedBranch() = withTestEnvironment { | ||
gitInit() | ||
gitCommit("Empty") | ||
testCommand({ repoInit("main", Optional.None) }) | ||
gitCreateAndCheckoutBranch("change-a") | ||
|
||
testCommand({ branchCreate("change-b") }) { | ||
awaitFrame( | ||
static = "Cannot branch from change-a since it is not tracked. Please track with st branch track.", | ||
output = "", | ||
) | ||
|
||
assertThat(awaitResult()).isFalse() | ||
} | ||
|
||
withDatabase { | ||
assertThat(it.branchQueries.selectAll().executeAsList().map { it.name }) | ||
.containsExactly("main") | ||
} | ||
} | ||
} |