Skip to content
Open
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
@@ -0,0 +1,93 @@
package io.github.typesafegithub.workflows.jitbindingserver

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.ktor.http.Parameters
import io.ktor.http.ParametersBuilder

class ActionCoordsTest :
FunSpec(
{
test("extractActionCoords parses owner/name with version and no path, FULL by default") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using context("extractActionCoords"), in case we need to add tests for some other function? Then we could remove the function name from individual test cases.

val parameters = createParameters(owner = "o", name = "act", version = "v1")

parameters.extractActionCoords(true) shouldBe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In every test, let's used named arguments - extractActionCoords(true) doesn't look readable.

ActionCoords(
owner = "o",
name = "act",
version = "v1",
significantVersion = FULL,
path = null,
)
}

test("extractActionCoords parses owner/name with path and significant version suffix") {
val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9")

parameters.extractActionCoords(true) shouldBe
ActionCoords(
owner = "o",
name = "act",
version = "v9",
significantVersion = MAJOR,
path = "p1/p2",
)
}

test("when extractVersion=false, version field is set to 'irrelevant'") {
val parameters = createParameters(owner = "o", name = "act___minor")

parameters.extractActionCoords(false) shouldBe
ActionCoords(
owner = "o",
name = "act",
version = "irrelevant",
significantVersion = MINOR,
path = null,
)
}

test("unknown significant version part falls back to FULL") {
val parameters = createParameters(owner = "o", name = "act___weird")

parameters.extractActionCoords(false) shouldBe
ActionCoords(
owner = "o",
name = "act",
version = "irrelevant",
significantVersion = FULL,
path = null,
)
}

test("handles name with underscores/hyphens and path segments") {
val parameters =
createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2")

parameters.extractActionCoords(true) shouldBe
ActionCoords(
owner = "o",
name = "my_action-name",
version = "v2",
significantVersion = MINOR,
path = "dir_one/dir-two",
)
}
},
)

private fun createParameters(
owner: String,
name: String,
version: String? = null,
): Parameters =
ParametersBuilder()
.apply {
append("owner", owner)
append("name", name)
version?.let { append("version", it) }
}.build()
Loading