fix broken tests

This commit is contained in:
Adam 2022-04-20 12:58:04 +02:00
parent 03e8e9442a
commit d1353eec60
4 changed files with 929 additions and 869 deletions

View file

@ -79,9 +79,7 @@ class ColourHexTest : BehaviorSpec({
val colour: Colour = jsonMapperKafkatorio.decodeFromString(colourJson)
val colourHex = colour.toHex()
colourHex shouldBe ColourHex(r, g, b, a)
}
}
}
})

View file

@ -1,5 +1,18 @@
package dev.adamko.kafkatorio.events.schema
import dev.adamko.kafkatorio.schema.common.Colour
import dev.adamko.kafkatorio.schema.common.EntityIdentifiersData
import dev.adamko.kafkatorio.schema.common.ForceIndex
import dev.adamko.kafkatorio.schema.common.MapEntityPosition
import dev.adamko.kafkatorio.schema.common.PlayerIndex
import dev.adamko.kafkatorio.schema.common.SurfaceIndex
import dev.adamko.kafkatorio.schema.common.Tick
import dev.adamko.kafkatorio.schema.common.UnitNumber
import dev.adamko.kafkatorio.schema.jsonMapperKafkatorio
import dev.adamko.kafkatorio.schema2.KafkatorioPacket2
import dev.adamko.kafkatorio.schema2.PlayerUpdate
import dev.adamko.kafkatorio.schema2.PlayerUpdateKey
import dev.adamko.kafkatorio.schema2.SurfaceUpdate
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import kotlinx.serialization.decodeFromString
@ -13,8 +26,9 @@ class UpdatePacketsTest : FunSpec({
{
"tick": 66,
"modVersion": "0.3.2",
"packetType": "UPDATE",
"update": {
"data": {
"type": "dev.adamko.kafkatorio.schema2.PlayerUpdate",
"key": {"index": 1},
"afkTime": 0,
"chatColour": {
"red": 1,
@ -33,7 +47,6 @@ class UpdatePacketsTest : FunSpec({
"on_player_joined_game": 1
},
"forceIndex": 1,
"index": 1,
"isAdmin": true,
"isConnected": true,
"isShowOnMap": true,
@ -41,23 +54,20 @@ class UpdatePacketsTest : FunSpec({
"lastOnline": 0,
"name": "fredthedeadhead",
"onlineTime": 0,
"position": {
"y": 13,
"x": -58
},
"tag": "",
"updateType": "PLAYER"
"position": [-58, 13],
"tag": ""
}
}
""".trimIndent()
test("decode") {
val packet: FactorioEventUpdatePacket = jsonMapperKafkatorio.decodeFromString(json)
val packet: KafkatorioPacket2 = jsonMapperKafkatorio.decodeFromString(json)
packet shouldBe FactorioEventUpdatePacket(
packet shouldBe KafkatorioPacket2(
modVersion = "0.3.2",
tick = Tick(66u),
update = PlayerUpdate(
data = PlayerUpdate(
key = PlayerUpdateKey(PlayerIndex(1u)),
afkTime = Tick(0u),
bannedReason = null,
characterUnitNumber = null,
@ -67,7 +77,6 @@ class UpdatePacketsTest : FunSpec({
disconnectReason = null,
eventCounts = mapOf("on_player_changed_position" to 7u, "on_player_joined_game" to 1u),
forceIndex = ForceIndex(1u),
index = PlayerIndex(1u),
isAdmin = true,
isConnected = true,
isRemoved = null,
@ -86,11 +95,11 @@ class UpdatePacketsTest : FunSpec({
}
test("encode") {
val v = FactorioEventUpdatePacket(
val v = KafkatorioPacket2(
modVersion = "0.3.2",
tick = Tick(66u),
update = PlayerUpdate(
index = PlayerIndex(1u),
data = PlayerUpdate(
key = PlayerUpdateKey(PlayerIndex(1u)),
characterUnitNumber = null,
chatColour = null,
colour = null,
@ -121,21 +130,22 @@ class UpdatePacketsTest : FunSpec({
{
"modVersion": "0.3.2",
"tick": 66,
"update": {
"index": 1,
"data": {
"type": "dev.adamko.kafkatorio.schema2.PlayerUpdate",
"key": {
"index": 1
},
"name": "fredthedeadhead",
"afkTime": 0,
"isShowOnMap": true,
"isSpectator": false,
"lastOnline": 0,
"onlineTime": 0,
"position": {
"x": -58.0,
"y": 13.0
},
"updateType": "PLAYER"
},
"packetType": "UPDATE"
"position": [
-58.0,
13.0
]
}
}
""".trimIndent()
}
@ -147,10 +157,11 @@ class UpdatePacketsTest : FunSpec({
{
"tick": 227934,
"modVersion": "0.3.2",
"packetType": "UPDATE",
"update": {
"index": 1,
"updateType": "PLAYER",
"data": {
"type": "dev.adamko.kafkatorio.schema2.PlayerUpdate",
"key": {
"index": 1
},
"lastOnline": 227932,
"onlineTime": 227888,
"afkTime": 324,
@ -158,7 +169,7 @@ class UpdatePacketsTest : FunSpec({
"diedCause": {
"unitNumber": 66,
"name": "small-biter",
"type": "unit"
"protoType": "unit"
},
"eventCounts": {
"on_player_died": 2
@ -168,12 +179,12 @@ class UpdatePacketsTest : FunSpec({
""".trimIndent()
test("decode") {
val packet: FactorioEventUpdatePacket = jsonMapperKafkatorio.decodeFromString(json)
val packet: KafkatorioPacket2 = jsonMapperKafkatorio.decodeFromString(json)
packet shouldBe FactorioEventUpdatePacket(
packet shouldBe KafkatorioPacket2(
modVersion = "0.3.2",
tick = Tick(227934u),
update = PlayerUpdate(
data = PlayerUpdate(
afkTime = Tick(324u),
bannedReason = null,
characterUnitNumber = null,
@ -182,12 +193,12 @@ class UpdatePacketsTest : FunSpec({
diedCause = EntityIdentifiersData(
unitNumber = UnitNumber(66u),
name = "small-biter",
type = "unit",
protoType = "unit",
),
disconnectReason = null,
eventCounts = mapOf("on_player_died" to 2u),
forceIndex = null,
index = PlayerIndex(1u),
key = PlayerUpdateKey(PlayerIndex(1u)),
isAdmin = null,
isConnected = true,
isRemoved = null,
@ -204,7 +215,38 @@ class UpdatePacketsTest : FunSpec({
)
)
}
}
context("surface update") {
//language=json
val json = """
{
"data": {
"type": "dev.adamko.kafkatorio.schema2.SurfaceUpdate",
"name": "nauvis",
"index": 1,
"daytime": 0.73
},
"modVersion": "0.3.2",
"tick": 176000
}
""".trimIndent()
val expected = KafkatorioPacket2(
tick = Tick(176000u),
modVersion = "0.3.2",
data = SurfaceUpdate(
name = "nauvis",
index = SurfaceIndex(1u),
daytime = 0.73,
)
)
println(jsonMapperKafkatorio.encodeToString(expected))
test("decode") {
val packet: KafkatorioPacket2 = jsonMapperKafkatorio.decodeFromString(json)
packet shouldBe expected
}
}
})

View file

@ -1,12 +1,19 @@
package dev.adamko.kafkatorio.processor.topology
import dev.adamko.kafkatorio.processor.KafkatorioTopology
import dev.adamko.kafkatorio.processor.admin.TOPIC_GROUPED_MAP_CHUNKS_STATE
import dev.adamko.kafkatorio.processor.serdes.jsonMapper
import dev.adamko.kafkatorio.processor.serdes.kxsBinary
import dev.adamko.kafkatorio.schema.common.*
import dev.adamko.kafkatorio.schema.common.Colour
import dev.adamko.kafkatorio.schema.common.ColourHex
import dev.adamko.kafkatorio.schema.common.MapChunkPosition
import dev.adamko.kafkatorio.schema.common.MapTileDictionary
import dev.adamko.kafkatorio.schema.common.MapTileDictionary.PrototypeKey
import dev.adamko.kafkatorio.schema.common.MapTilePosition
import dev.adamko.kafkatorio.schema.common.PrototypeName
import dev.adamko.kafkatorio.schema.common.SurfaceIndex
import dev.adamko.kafkatorio.schema.common.Tick
import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype2
import dev.adamko.kafkatorio.schema2.KafkatorioPacket2
import dev.adamko.kafkatorio.schema2.MapChunkUpdate
import dev.adamko.kafkatorio.schema2.MapChunkUpdateKey
import dev.adamko.kafkatorio.schema2.PrototypesUpdate
@ -28,57 +35,65 @@ class GroupMapChunksTest : FunSpec({
test("basic test") {
val streamsBuilder = StreamsBuilder()
val prototypesTopicName = "prototypes-topic"
val mapChunkUpdatesTopicName = "map-chunk-updates-topic"
val prototypesTopicName = "kafkatorio.packet.prototypes"
val mapChunkUpdatesTopicName = "kafkatorio.packet.map-chunk"
val topology = groupMapChunks(streamsBuilder)
val testDriver = TopologyTestDriver(topology)
val prototypesTestInputTopic: TestInputTopic<FactorioServerId, PrototypesUpdate> =
val prototypesTestInputTopic: TestInputTopic<FactorioServerId, KafkatorioPacket2> =
testDriver.createInputTopic(
prototypesTopicName,
jsonMapper.serde<FactorioServerId>().serializer(),
jsonMapper.serde<PrototypesUpdate>().serializer(),
jsonMapper.serde<KafkatorioPacket2>().serializer(),
)
val serverId = FactorioServerId("test-server-id")
prototypesTestInputTopic.pipeInput(
serverId,
PrototypesUpdate(
listOf(
FactorioPrototype2.MapTile(
PrototypeName("fake-proto"),
layer = 1u,
mapColour = Colour(0.3f, 0.2f, 0.1f, 1.0f),
collisionMasks = listOf("fake-mask"),
order = "fake-order",
canBeMined = false,
KafkatorioPacket2(
modVersion = "1.2.3",
tick = Tick(22u),
PrototypesUpdate(
listOf(
FactorioPrototype2.MapTile(
PrototypeName("fake-proto"),
layer = 1u,
mapColour = Colour(0.3f, 0.2f, 0.1f, 1.0f),
collisionMasks = listOf("fake-mask"),
order = "fake-order",
canBeMined = false,
)
)
)
)
)
val mapChunkUpdatesInputTopic: TestInputTopic<FactorioServerId, MapChunkUpdate> =
val mapChunkUpdatesInputTopic: TestInputTopic<FactorioServerId, KafkatorioPacket2> =
testDriver.createInputTopic(
mapChunkUpdatesTopicName,
jsonMapper.serde<FactorioServerId>().serializer(),
jsonMapper.serde<MapChunkUpdate>().serializer(),
jsonMapper.serde<KafkatorioPacket2>().serializer(),
)
mapChunkUpdatesInputTopic.pipeInput(
serverId,
MapChunkUpdate(
key = MapChunkUpdateKey(
MapChunkPosition(11, 22),
SurfaceIndex(1u),
),
tileDictionary = MapTileDictionary(
tilesXY = mapOf(
"1" to mapOf("2" to PrototypeKey(33))
KafkatorioPacket2(
modVersion = "1.2.3",
tick = Tick(44u),
MapChunkUpdate(
key = MapChunkUpdateKey(
MapChunkPosition(11, 22),
SurfaceIndex(1u),
),
protos = mapOf(PrototypeName("fake-proto") to PrototypeKey(33))
tileDictionary = MapTileDictionary(
tilesXY = mapOf(
"1" to mapOf("2" to PrototypeKey(33))
),
protos = mapOf(PrototypeName("fake-proto") to PrototypeKey(33))
)
)
)
)
@ -114,5 +129,4 @@ class GroupMapChunksTest : FunSpec({
}
}
}
})