Skip to content

Commit 92f9b64

Browse files
authored
test(abg): exercise JAR mode for all typings (#1335)
To ensure the code compiles fine.
1 parent a18562f commit 92f9b64

File tree

2 files changed

+139
-49
lines changed

2 files changed

+139
-49
lines changed

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionForGeneratedJar.kt

Lines changed: 137 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,43 @@
44
@file:Suppress(
55
"DataClassPrivateConstructor",
66
"UNUSED_PARAMETER",
7-
"DEPRECATION",
87
)
98

109
package io.github.typesafegithub.workflows.actions.johnsmith
1110

1211
import io.github.typesafegithub.workflows.domain.actions.Action
1312
import io.github.typesafegithub.workflows.domain.actions.RegularAction
1413
import java.util.LinkedHashMap
15-
import kotlin.Deprecated
14+
import kotlin.Boolean
15+
import kotlin.Float
16+
import kotlin.Int
1617
import kotlin.String
1718
import kotlin.Suppress
1819
import kotlin.Unit
20+
import kotlin.collections.List
1921
import kotlin.collections.Map
2022
import kotlin.collections.toList
2123
import kotlin.collections.toTypedArray
2224

2325
/**
2426
* Action: Do something cool
25-
* and describe it in multiple lines
2627
*
2728
* This is a test description that should be put in the KDoc comment for a class
2829
*
2930
* [Action on GitHub](https://github.com/john-smith/action-for-generated-jar)
3031
*
3132
* @param fooBar Short description
32-
* @param bazGoo Just another input
33-
* with multiline description
33+
* @param bazGoo First boolean input!
34+
* @param binKin Boolean and nullable
35+
* @param intPint Integer
36+
* @param floPint Float
37+
* @param finBin Enumeration
38+
* @param gooZen Integer with special value
39+
* @param bahEnum Enum with custom naming
40+
* @param listStrings List of strings
41+
* @param listInts List of integers
42+
* @param listEnums List of enums
43+
* @param listIntSpecial List of integer with special values
3444
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by
3545
* the binding
3646
* @param _customVersion Allows overriding action's version, for example to use a specific minor
@@ -42,11 +52,49 @@ public data class ActionForGeneratedJar private constructor(
4252
*/
4353
public val fooBar: String,
4454
/**
45-
* Just another input
46-
* with multiline description
55+
* First boolean input!
4756
*/
48-
@Deprecated("this is deprecated")
49-
public val bazGoo: ActionForGeneratedJar.BazGoo,
57+
public val bazGoo: Boolean,
58+
/**
59+
* Boolean and nullable
60+
*/
61+
public val binKin: Boolean? = null,
62+
/**
63+
* Integer
64+
*/
65+
public val intPint: Int,
66+
/**
67+
* Float
68+
*/
69+
public val floPint: Float,
70+
/**
71+
* Enumeration
72+
*/
73+
public val finBin: ActionForGeneratedJar.Bin,
74+
/**
75+
* Integer with special value
76+
*/
77+
public val gooZen: ActionForGeneratedJar.Zen,
78+
/**
79+
* Enum with custom naming
80+
*/
81+
public val bahEnum: ActionForGeneratedJar.BahEnum,
82+
/**
83+
* List of strings
84+
*/
85+
public val listStrings: List<String>? = null,
86+
/**
87+
* List of integers
88+
*/
89+
public val listInts: List<Int>? = null,
90+
/**
91+
* List of enums
92+
*/
93+
public val listEnums: List<ActionForGeneratedJar.MyEnum>? = null,
94+
/**
95+
* List of integer with special values
96+
*/
97+
public val listIntSpecial: List<ActionForGeneratedJar.MyInt>? = null,
5098
/**
5199
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
52100
*/
@@ -61,30 +109,103 @@ public data class ActionForGeneratedJar private constructor(
61109
public constructor(
62110
vararg pleaseUseNamedArguments: Unit,
63111
fooBar: String,
64-
bazGoo: ActionForGeneratedJar.BazGoo,
112+
bazGoo: Boolean,
113+
binKin: Boolean? = null,
114+
intPint: Int,
115+
floPint: Float,
116+
finBin: ActionForGeneratedJar.Bin,
117+
gooZen: ActionForGeneratedJar.Zen,
118+
bahEnum: ActionForGeneratedJar.BahEnum,
119+
listStrings: List<String>? = null,
120+
listInts: List<Int>? = null,
121+
listEnums: List<ActionForGeneratedJar.MyEnum>? = null,
122+
listIntSpecial: List<ActionForGeneratedJar.MyInt>? = null,
65123
_customInputs: Map<String, String> = mapOf(),
66124
_customVersion: String? = null,
67-
) : this(fooBar=fooBar, bazGoo=bazGoo, _customInputs=_customInputs,
68-
_customVersion=_customVersion)
125+
) : this(fooBar=fooBar, bazGoo=bazGoo, binKin=binKin, intPint=intPint, floPint=floPint,
126+
finBin=finBin, gooZen=gooZen, bahEnum=bahEnum, listStrings=listStrings,
127+
listInts=listInts, listEnums=listEnums, listIntSpecial=listIntSpecial,
128+
_customInputs=_customInputs, _customVersion=_customVersion)
69129

70130
@Suppress("SpreadOperator")
71131
override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
72132
*listOfNotNull(
73133
"foo-bar" to fooBar,
74-
"baz-goo" to bazGoo.stringValue,
134+
"baz-goo" to bazGoo.toString(),
135+
binKin?.let { "bin-kin" to it.toString() },
136+
"int-pint" to intPint.toString(),
137+
"flo-pint" to floPint.toString(),
138+
"fin-bin" to finBin.stringValue,
139+
"goo-zen" to gooZen.integerValue.toString(),
140+
"bah-enum" to bahEnum.stringValue,
141+
listStrings?.let { "list-strings" to it.joinToString(",") },
142+
listInts?.let { "list-ints" to it.joinToString(",") { it.toString() } },
143+
listEnums?.let { "list-enums" to it.joinToString(",") { it.stringValue } },
144+
listIntSpecial?.let { "list-int-special" to it.joinToString(",") {
145+
it.integerValue.toString() } },
75146
*_customInputs.toList().toTypedArray(),
76147
).toTypedArray()
77148
)
78149

79150
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
80151

81-
public sealed class BazGoo(
152+
public sealed class Bin(
82153
public val stringValue: String,
83154
) {
84-
public object HelloWorld : ActionForGeneratedJar.BazGoo("helloworld")
155+
public object Foo : ActionForGeneratedJar.Bin("foo")
156+
157+
public object BooBar : ActionForGeneratedJar.Bin("boo-bar")
158+
159+
public object Baz123 : ActionForGeneratedJar.Bin("baz123")
85160

86161
public class Custom(
87162
customStringValue: String,
88-
) : ActionForGeneratedJar.BazGoo(customStringValue)
163+
) : ActionForGeneratedJar.Bin(customStringValue)
164+
}
165+
166+
public sealed class Zen(
167+
public val integerValue: Int,
168+
) {
169+
public class Value(
170+
requestedValue: Int,
171+
) : ActionForGeneratedJar.Zen(requestedValue)
172+
173+
public object Special1 : ActionForGeneratedJar.Zen(3)
174+
175+
public object Special2 : ActionForGeneratedJar.Zen(-1)
176+
}
177+
178+
public sealed class BahEnum(
179+
public val stringValue: String,
180+
) {
181+
public object HelloWorld : ActionForGeneratedJar.BahEnum("helloworld")
182+
183+
public class Custom(
184+
customStringValue: String,
185+
) : ActionForGeneratedJar.BahEnum(customStringValue)
186+
}
187+
188+
public sealed class MyEnum(
189+
public val stringValue: String,
190+
) {
191+
public object One : ActionForGeneratedJar.MyEnum("one")
192+
193+
public object Two : ActionForGeneratedJar.MyEnum("two")
194+
195+
public object Three : ActionForGeneratedJar.MyEnum("three")
196+
197+
public class Custom(
198+
customStringValue: String,
199+
) : ActionForGeneratedJar.MyEnum(customStringValue)
200+
}
201+
202+
public sealed class MyInt(
203+
public val integerValue: Int,
204+
) {
205+
public class Value(
206+
requestedValue: Int,
207+
) : ActionForGeneratedJar.MyInt(requestedValue)
208+
209+
public object TheAnswer : ActionForGeneratedJar.MyInt(42)
89210
}
90211
}

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -501,48 +501,17 @@ class GenerationTest : FunSpec({
501501

502502
test("action binding generated for the versioned JAR") {
503503
// given
504-
val actionManifest =
505-
Metadata(
506-
name =
507-
"""
508-
Do something cool
509-
and describe it in multiple lines
510-
""".trimIndent(),
511-
description = "This is a test description that should be put in the KDoc comment for a class",
512-
inputs =
513-
mapOf(
514-
"foo-bar" to
515-
Input(
516-
description = "Short description",
517-
required = true,
518-
default = null,
519-
),
520-
"baz-goo" to
521-
Input(
522-
description =
523-
"""
524-
Just another input
525-
with multiline description
526-
""".trimIndent(),
527-
deprecationMessage = "this is deprecated",
528-
required = true,
529-
default = null,
530-
),
531-
),
532-
)
533504
val coords = ActionCoords("john-smith", "action-for-generated-jar", "v3")
534505

535506
// when
536507
val binding =
537508
coords.generateBinding(
538509
metadataRevision = FromLockfile,
539-
metadata = actionManifest,
510+
metadata = actionManifestWithAllTypesOfInputs,
540511
clientType = ClientType.VERSIONED_JAR,
541512
inputTypings =
542513
Pair(
543-
mapOf(
544-
"baz-goo" to EnumTyping(null, listOf("helloworld"), listOf("HelloWorld")),
545-
),
514+
typingsForAllTypesOfInputs,
546515
ACTION,
547516
),
548517
)

0 commit comments

Comments
 (0)