35 lines
2.9 KiB
Go
35 lines
2.9 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestCopyGameClientBridgeDeclarationsCopiesQueryTemplateSlices(t *testing.T) {
|
|
manifest := GameClientBridgeManifest{
|
|
QueryTemplates: []GameClientBridgeQueryTemplateDeclaration{{Key: "player.lookup", PollIntervalSeconds: 3, SQLRef: "sql/player-lookup.sql"}},
|
|
LogProjections: []GameClientBridgeLogProjectionDeclaration{{
|
|
Key: "player.login", StreamKeys: []string{"process.stdout"}, Steps: []GameClientBridgeLogProjectionStepDeclaration{{Pattern: `Player (?<slot>\d+)`}}, CorrelationFields: []string{"slot"}, MaxInterveningLines: 8,
|
|
Target: GameClientBridgeLogProjectionTargetDeclaration{Collection: "users", UpsertKeys: []string{"steamId"}, CaptureMappings: map[string]string{"steamId": "steamId"}, FixedValues: map[string]string{"source": "stdout"}, ObservedAtField: "lastLoginAt"},
|
|
Presence: &GameClientBridgeLogProjectionPresenceDeclaration{TimestampField: "lastLoginAt", ActiveWindowSeconds: 600, ActivityTarget: &GameClientBridgeLogProjectionTargetDeclaration{Collection: "activity", UpsertKeys: []string{"steamId"}, CaptureMappings: map[string]string{"steamId": "steamId"}}},
|
|
}},
|
|
DataPacks: []GameClientBridgeDataPackDeclaration{{Key: "db-v1", LogParserRefs: []string{"logs.json"}, ConfigMapRefs: []string{"config.json"}, DataRefs: []string{"data.json"}}},
|
|
Pages: []GameClientBridgePageContract{{PageKey: "players", QueryTemplateKeys: []string{"player.lookup"}}},
|
|
}
|
|
manifestCopy := CopyGameClientBridgeManifest(manifest)
|
|
manifestCopy.QueryTemplates[0].Key = "mutated"
|
|
manifestCopy.LogProjections[0].StreamKeys[0] = "mutated"
|
|
manifestCopy.LogProjections[0].Target.CaptureMappings["steamId"] = "mutated"
|
|
manifestCopy.LogProjections[0].Presence.ActivityTarget.CaptureMappings["steamId"] = "mutated"
|
|
manifestCopy.DataPacks[0].LogParserRefs[0] = "mutated"
|
|
manifestCopy.DataPacks[0].DataRefs[0] = "mutated"
|
|
manifestCopy.Pages[0].QueryTemplateKeys[0] = "mutated"
|
|
if manifest.QueryTemplates[0].Key != "player.lookup" || manifest.QueryTemplates[0].SQLRef != "sql/player-lookup.sql" || manifest.LogProjections[0].StreamKeys[0] != "process.stdout" || manifest.LogProjections[0].Target.CaptureMappings["steamId"] != "steamId" || manifest.LogProjections[0].Presence.ActivityTarget.CaptureMappings["steamId"] != "steamId" || manifest.DataPacks[0].LogParserRefs[0] != "logs.json" || manifest.DataPacks[0].DataRefs[0] != "data.json" || manifest.Pages[0].QueryTemplateKeys[0] != "player.lookup" {
|
|
t.Fatalf("manifest copy aliases query template declarations: source=%#v copy=%#v", manifest, manifestCopy)
|
|
}
|
|
|
|
status := GameClientBridgeStatus{Profiles: []GameClientBridgeProfileDeclaration{{QueryTemplateKeys: []string{"player.lookup"}}}}
|
|
statusCopy := CopyGameClientBridgeStatus(status)
|
|
statusCopy.Profiles[0].QueryTemplateKeys[0] = "mutated"
|
|
if status.Profiles[0].QueryTemplateKeys[0] != "player.lookup" {
|
|
t.Fatalf("status copy aliases query template keys: source=%#v copy=%#v", status, statusCopy)
|
|
}
|
|
}
|