@@ -13,10 +13,10 @@ class DeviceActivityReporterTest {
1313
1414 @Test
1515 fun `report counts lastSeen windows and currently connected devices` () {
16- val oneHour = device(version = " octi/1.0.0" , lastSeen = now.minus(Duration .ofMinutes(10 )))
17- val twentyFourHours = device(version = " octi/2.0.0" , lastSeen = now.minus(Duration .ofHours(2 )))
18- val connected = device(version = " octi/3.0.0" , lastSeen = now.minus(Duration .ofHours(30 )))
19- val inactive = device(version = " octi/4.0.0" , lastSeen = now.minus(Duration .ofHours(30 )))
16+ val oneHour = device(version = " octi/1.0.0/FOSS " , lastSeen = now.minus(Duration .ofMinutes(10 )))
17+ val twentyFourHours = device(version = " octi/2.0.0/GPLAY " , lastSeen = now.minus(Duration .ofHours(2 )))
18+ val connected = device(version = " octi/3.0.0/GPLAY " , lastSeen = now.minus(Duration .ofHours(30 )))
19+ val inactive = device(version = " octi/4.0.0/FOSS " , lastSeen = now.minus(Duration .ofHours(30 )))
2020
2121 val report = DeviceActivityReporter .buildReport(
2222 devices = listOf (oneHour, twentyFourHours, connected, inactive),
@@ -26,33 +26,43 @@ class DeviceActivityReporterTest {
2626
2727 report.oneHour.total shouldBe 2
2828 report.oneHour.versionCounts() shouldBe mapOf (
29- " octi/1.0.0" to 1 ,
30- " octi/3.0.0" to 1 ,
29+ " octi/1.0.0/FOSS" to 1 ,
30+ " octi/3.0.0/GPLAY" to 1 ,
31+ )
32+ report.oneHour.buildFlavorCounts() shouldBe mapOf (
33+ " FOSS" to 1 ,
34+ " GPLAY" to 1 ,
3135 )
3236
3337 report.twentyFourHours.total shouldBe 3
3438 report.twentyFourHours.versionCounts() shouldBe mapOf (
35- " octi/1.0.0" to 1 ,
36- " octi/2.0.0" to 1 ,
37- " octi/3.0.0" to 1 ,
39+ " octi/1.0.0/FOSS" to 1 ,
40+ " octi/2.0.0/GPLAY" to 1 ,
41+ " octi/3.0.0/GPLAY" to 1 ,
42+ )
43+ report.twentyFourHours.buildFlavorCounts() shouldBe mapOf (
44+ " FOSS" to 1 ,
45+ " GPLAY" to 2 ,
3846 )
3947 }
4048
4149 @Test
4250 fun `report formats counts and percentages sorted by count` () {
4351 val report = DeviceActivityReporter .buildReport(
4452 devices = listOf (
45- device(version = " octi/1.0.0" , lastSeen = now),
46- device(version = " octi/1.0.0" , lastSeen = now),
47- device(version = " octi/2.0.0" , lastSeen = now),
53+ device(version = " octi/1.0.0/FOSS " , lastSeen = now),
54+ device(version = " octi/1.0.0/FOSS " , lastSeen = now),
55+ device(version = " octi/2.0.0/GPLAY " , lastSeen = now),
4856 ),
4957 activeDeviceKeys = emptySet(),
5058 now = now,
5159 )
5260
5361 DeviceActivityReporter .formatReport(report) shouldBe
54- " device-stats: 1h total=3 versions=[octi/1.0.0=2 (66.7%), octi/2.0.0=1 (33.3%)]; " +
55- " 24h total=3 versions=[octi/1.0.0=2 (66.7%), octi/2.0.0=1 (33.3%)]"
62+ " device-stats: 1h total=3 versions=[octi/1.0.0/FOSS=2 (66.7%), octi/2.0.0/GPLAY=1 (33.3%)] " +
63+ " flavors=[FOSS=2 (66.7%), GPLAY=1 (33.3%)]; " +
64+ " 24h total=3 versions=[octi/1.0.0/FOSS=2 (66.7%), octi/2.0.0/GPLAY=1 (33.3%)] " +
65+ " flavors=[FOSS=2 (66.7%), GPLAY=1 (33.3%)]"
5666 }
5767
5868 @Test
@@ -64,6 +74,7 @@ class DeviceActivityReporterTest {
6474 )
6575 empty.oneHour.total shouldBe 0
6676 empty.oneHour.versions shouldBe emptyList()
77+ empty.oneHour.buildFlavors shouldBe emptyList()
6778
6879 val report = DeviceActivityReporter .buildReport(
6980 devices = listOf (
@@ -81,6 +92,13 @@ class DeviceActivityReporterTest {
8192 percent = 100.0 ,
8293 )
8394 )
95+ report.oneHour.buildFlavors shouldBe listOf (
96+ DeviceActivityReporter .BuildFlavorStats (
97+ flavor = " <unknown>" ,
98+ count = 2 ,
99+ percent = 100.0 ,
100+ )
101+ )
84102 }
85103
86104 @Test
@@ -121,10 +139,23 @@ class DeviceActivityReporterTest {
121139 sanitized.endsWith(" ..." ) shouldBe true
122140 }
123141
142+ @Test
143+ fun `build flavor is parsed from user-agent style versions` () {
144+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/FOSS" ) shouldBe " FOSS"
145+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/gplay/dev-a1b2c3d" ) shouldBe " GPLAY"
146+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/GPLATE" ) shouldBe " GPLAY"
147+ DeviceActivityReporter .buildFlavorForLog(" 1.2.3" ) shouldBe " <unknown>"
148+ DeviceActivityReporter .buildFlavorForLog(null ) shouldBe " <unknown>"
149+ }
150+
124151 private fun DeviceActivityReporter.WindowStats.versionCounts (): Map <String , Int > {
125152 return versions.associate { it.version to it.count }
126153 }
127154
155+ private fun DeviceActivityReporter.WindowStats.buildFlavorCounts (): Map <String , Int > {
156+ return buildFlavors.associate { it.flavor to it.count }
157+ }
158+
128159 private fun device (
129160 version : String? ,
130161 lastSeen : Instant ,
0 commit comments