Skip to content

Commit 29562ba

Browse files
authored
test(abg): create test case with all types of inputs (#1333)
In a single test case, let's exercise the generator against all possible types of inputs.
1 parent f3cdd81 commit 29562ba

File tree

5 files changed

+111
-241
lines changed

5 files changed

+111
-241
lines changed

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNonStringInputsV3.kt renamed to action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithAllTypesOfInputsV3.kt

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,26 @@ import kotlin.collections.toTypedArray
2727
*
2828
* This is a test description that should be put in the KDoc comment for a class
2929
*
30-
* [Action on GitHub](https://github.com/john-smith/action-with-non-string-inputs)
30+
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs)
3131
*
3232
* @param fooBar Short description
3333
* @param bazGoo First boolean input!
3434
* @param binKin Boolean and nullable
3535
* @param intPint Integer
3636
* @param floPint Float
37-
* @param booZoo List of strings
3837
* @param finBin Enumeration
3938
* @param gooZen Integer with special value
4039
* @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
4144
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by
4245
* the binding
4346
* @param _customVersion Allows overriding action's version, for example to use a specific minor
4447
* version, or a newer version that the binding doesn't yet know about
4548
*/
46-
public data class ActionWithNonStringInputsV3 private constructor(
49+
public data class ActionWithAllTypesOfInputsV3 private constructor(
4750
/**
4851
* Short description
4952
*/
@@ -64,22 +67,34 @@ public data class ActionWithNonStringInputsV3 private constructor(
6467
* Float
6568
*/
6669
public val floPint: Float,
67-
/**
68-
* List of strings
69-
*/
70-
public val booZoo: List<String>,
7170
/**
7271
* Enumeration
7372
*/
74-
public val finBin: ActionWithNonStringInputsV3.Bin,
73+
public val finBin: ActionWithAllTypesOfInputsV3.Bin,
7574
/**
7675
* Integer with special value
7776
*/
78-
public val gooZen: ActionWithNonStringInputsV3.Zen,
77+
public val gooZen: ActionWithAllTypesOfInputsV3.Zen,
7978
/**
8079
* Enum with custom naming
8180
*/
82-
public val bahEnum: ActionWithNonStringInputsV3.BahEnum,
81+
public val bahEnum: ActionWithAllTypesOfInputsV3.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<ActionWithAllTypesOfInputsV3.MyEnum>? = null,
94+
/**
95+
* List of integer with special values
96+
*/
97+
public val listIntSpecial: List<ActionWithAllTypesOfInputsV3.MyInt>? = null,
8398
/**
8499
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
85100
*/
@@ -89,7 +104,7 @@ public data class ActionWithNonStringInputsV3 private constructor(
89104
* version that the binding doesn't yet know about
90105
*/
91106
public val _customVersion: String? = null,
92-
) : RegularAction<Action.Outputs>("john-smith", "action-with-non-string-inputs", _customVersion ?:
107+
) : RegularAction<Action.Outputs>("john-smith", "action-with-all-types-of-inputs", _customVersion ?:
93108
"v3") {
94109
public constructor(
95110
vararg pleaseUseNamedArguments: Unit,
@@ -98,14 +113,18 @@ public data class ActionWithNonStringInputsV3 private constructor(
98113
binKin: Boolean? = null,
99114
intPint: Int,
100115
floPint: Float,
101-
booZoo: List<String>,
102-
finBin: ActionWithNonStringInputsV3.Bin,
103-
gooZen: ActionWithNonStringInputsV3.Zen,
104-
bahEnum: ActionWithNonStringInputsV3.BahEnum,
116+
finBin: ActionWithAllTypesOfInputsV3.Bin,
117+
gooZen: ActionWithAllTypesOfInputsV3.Zen,
118+
bahEnum: ActionWithAllTypesOfInputsV3.BahEnum,
119+
listStrings: List<String>? = null,
120+
listInts: List<Int>? = null,
121+
listEnums: List<ActionWithAllTypesOfInputsV3.MyEnum>? = null,
122+
listIntSpecial: List<ActionWithAllTypesOfInputsV3.MyInt>? = null,
105123
_customInputs: Map<String, String> = mapOf(),
106124
_customVersion: String? = null,
107125
) : this(fooBar=fooBar, bazGoo=bazGoo, binKin=binKin, intPint=intPint, floPint=floPint,
108-
booZoo=booZoo, finBin=finBin, gooZen=gooZen, bahEnum=bahEnum,
126+
finBin=finBin, gooZen=gooZen, bahEnum=bahEnum, listStrings=listStrings,
127+
listInts=listInts, listEnums=listEnums, listIntSpecial=listIntSpecial,
109128
_customInputs=_customInputs, _customVersion=_customVersion)
110129

111130
@Suppress("SpreadOperator")
@@ -116,10 +135,14 @@ public data class ActionWithNonStringInputsV3 private constructor(
116135
binKin?.let { "bin-kin" to it.toString() },
117136
"int-pint" to intPint.toString(),
118137
"flo-pint" to floPint.toString(),
119-
"boo-zoo" to booZoo.joinToString(","),
120138
"fin-bin" to finBin.stringValue,
121139
"goo-zen" to gooZen.integerValue.toString(),
122140
"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() } },
123146
*_customInputs.toList().toTypedArray(),
124147
).toTypedArray()
125148
)
@@ -129,36 +152,60 @@ public data class ActionWithNonStringInputsV3 private constructor(
129152
public sealed class Bin(
130153
public val stringValue: String,
131154
) {
132-
public object Foo : ActionWithNonStringInputsV3.Bin("foo")
155+
public object Foo : ActionWithAllTypesOfInputsV3.Bin("foo")
133156

134-
public object BooBar : ActionWithNonStringInputsV3.Bin("boo-bar")
157+
public object BooBar : ActionWithAllTypesOfInputsV3.Bin("boo-bar")
135158

136-
public object Baz123 : ActionWithNonStringInputsV3.Bin("baz123")
159+
public object Baz123 : ActionWithAllTypesOfInputsV3.Bin("baz123")
137160

138161
public class Custom(
139162
customStringValue: String,
140-
) : ActionWithNonStringInputsV3.Bin(customStringValue)
163+
) : ActionWithAllTypesOfInputsV3.Bin(customStringValue)
141164
}
142165

143166
public sealed class Zen(
144167
public val integerValue: Int,
145168
) {
146169
public class Value(
147170
requestedValue: Int,
148-
) : ActionWithNonStringInputsV3.Zen(requestedValue)
171+
) : ActionWithAllTypesOfInputsV3.Zen(requestedValue)
149172

150-
public object Special1 : ActionWithNonStringInputsV3.Zen(3)
173+
public object Special1 : ActionWithAllTypesOfInputsV3.Zen(3)
151174

152-
public object Special2 : ActionWithNonStringInputsV3.Zen(-1)
175+
public object Special2 : ActionWithAllTypesOfInputsV3.Zen(-1)
153176
}
154177

155178
public sealed class BahEnum(
156179
public val stringValue: String,
157180
) {
158-
public object HelloWorld : ActionWithNonStringInputsV3.BahEnum("helloworld")
181+
public object HelloWorld : ActionWithAllTypesOfInputsV3.BahEnum("helloworld")
182+
183+
public class Custom(
184+
customStringValue: String,
185+
) : ActionWithAllTypesOfInputsV3.BahEnum(customStringValue)
186+
}
187+
188+
public sealed class MyEnum(
189+
public val stringValue: String,
190+
) {
191+
public object One : ActionWithAllTypesOfInputsV3.MyEnum("one")
192+
193+
public object Two : ActionWithAllTypesOfInputsV3.MyEnum("two")
194+
195+
public object Three : ActionWithAllTypesOfInputsV3.MyEnum("three")
159196

160197
public class Custom(
161198
customStringValue: String,
162-
) : ActionWithNonStringInputsV3.BahEnum(customStringValue)
199+
) : ActionWithAllTypesOfInputsV3.MyEnum(customStringValue)
200+
}
201+
202+
public sealed class MyInt(
203+
public val integerValue: Int,
204+
) {
205+
public class Value(
206+
requestedValue: Int,
207+
) : ActionWithAllTypesOfInputsV3.MyInt(requestedValue)
208+
209+
public object TheAnswer : ActionWithAllTypesOfInputsV3.MyInt(42)
163210
}
164211
}

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNonStringInputsV3Test.kt renamed to action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithAllTypesOfInputsV3Test.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator.bindingsfromunittests
22

3-
import io.github.typesafegithub.workflows.actions.johnsmith.ActionWithNonStringInputsV3
3+
import io.github.typesafegithub.workflows.actions.johnsmith.ActionWithAllTypesOfInputsV3
44
import io.kotest.core.spec.style.DescribeSpec
55
import io.kotest.matchers.shouldBe
66

7-
class ActionWithNonStringInputsV3Test : DescribeSpec({
8-
it("correctly translates boolean inputs ") {
7+
class ActionWithAllTypesOfInputsV3Test : DescribeSpec({
8+
it("correctly translates all types of inputs") {
99
// given
10-
val action = ActionWithNonStringInputsV3(
10+
val action = ActionWithAllTypesOfInputsV3(
1111
fooBar = "test",
1212
bazGoo = true,
1313
binKin = false,
1414
intPint = 43,
1515
floPint = 123.456f,
16-
booZoo = listOf("foo", "bar"),
17-
finBin = ActionWithNonStringInputsV3.Bin.BooBar,
18-
gooZen = ActionWithNonStringInputsV3.Zen.Special1,
19-
bahEnum = ActionWithNonStringInputsV3.BahEnum.HelloWorld
16+
finBin = ActionWithAllTypesOfInputsV3.Bin.BooBar,
17+
gooZen = ActionWithAllTypesOfInputsV3.Zen.Special1,
18+
bahEnum = ActionWithAllTypesOfInputsV3.BahEnum.HelloWorld,
19+
listStrings = listOf("hello", "world"),
20+
listInts = listOf(1, 42),
21+
listEnums = listOf(ActionWithAllTypesOfInputsV3.MyEnum.One, ActionWithAllTypesOfInputsV3.MyEnum.Three),
22+
listIntSpecial = listOf(ActionWithAllTypesOfInputsV3.MyInt.TheAnswer, ActionWithAllTypesOfInputsV3.MyInt.Value(0))
2023
)
2124

2225
// when
@@ -29,25 +32,27 @@ class ActionWithNonStringInputsV3Test : DescribeSpec({
2932
"bin-kin" to "false",
3033
"int-pint" to "43",
3134
"flo-pint" to "123.456",
32-
"boo-zoo" to "foo,bar",
3335
"fin-bin" to "boo-bar",
3436
"goo-zen" to "3",
3537
"bah-enum" to "helloworld",
38+
"list-strings" to "hello,world",
39+
"list-ints" to "1,42",
40+
"list-enums" to "one,three",
41+
"list-int-special" to "42,0"
3642
)
3743
}
3844

3945
it("works for custom values") {
4046
// given
41-
val action = ActionWithNonStringInputsV3(
47+
val action = ActionWithAllTypesOfInputsV3(
4248
fooBar = "test",
4349
bazGoo = true,
4450
binKin = false,
4551
intPint = 43,
4652
floPint = 123.456f,
47-
booZoo = listOf("foo", "bar"),
48-
finBin = ActionWithNonStringInputsV3.Bin.Custom("this-is-custom!"),
49-
gooZen = ActionWithNonStringInputsV3.Zen.Value(123),
50-
bahEnum = ActionWithNonStringInputsV3.BahEnum.Custom("very-custom"),
53+
finBin = ActionWithAllTypesOfInputsV3.Bin.Custom("this-is-custom!"),
54+
gooZen = ActionWithAllTypesOfInputsV3.Zen.Value(123),
55+
bahEnum = ActionWithAllTypesOfInputsV3.BahEnum.Custom("very-custom"),
5156
)
5257

5358
// when
@@ -60,7 +65,6 @@ class ActionWithNonStringInputsV3Test : DescribeSpec({
6065
"bin-kin" to "false",
6166
"int-pint" to "43",
6267
"flo-pint" to "123.456",
63-
"boo-zoo" to "foo,bar",
6468
"fin-bin" to "this-is-custom!",
6569
"goo-zen" to "123",
6670
"bah-enum" to "very-custom",

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

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)