-
-
Notifications
You must be signed in to change notification settings - Fork 27
test(server): add unit tests for extractActionCoords function in ActionCoordsTest
#2140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeoColman
wants to merge
7
commits into
main
Choose a base branch
from
leocolman/tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
947707c
test(server): add unit tests for `extractActionCoords` function in `A…
LeoColman 7f19116
Merge branch 'main' into leocolman/tests
LeoColman 3a0299e
Fix linter
LeoColman 9deca8a
Fix linter
LeoColman 1ad136c
Merge branch 'main' into leocolman/tests
LeoColman 92b27e4
Remove failing test
LeoColman aea3645
Merge branch 'main' into leocolman/tests
LeoColman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...r/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt
This file contains hidden or 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,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") { | ||
| val parameters = createParameters(owner = "o", name = "act", version = "v1") | ||
|
|
||
| parameters.extractActionCoords(true) shouldBe | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In every test, let's used named arguments - |
||
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.