@@ -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,56 @@ 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+ """
63+ device-stats:
64+ 1h: total=3
65+ flavors:
66+ FOSS=2 (66.7%)
67+ GPLAY=1 (33.3%)
68+ versions:
69+ octi/1.0.0/FOSS=2 (66.7%)
70+ octi/2.0.0/GPLAY=1 (33.3%)
71+ 24h: total=3
72+ flavors:
73+ FOSS=2 (66.7%)
74+ GPLAY=1 (33.3%)
75+ versions:
76+ octi/1.0.0/FOSS=2 (66.7%)
77+ octi/2.0.0/GPLAY=1 (33.3%)
78+ """ .trimIndent()
5679 }
5780
5881 @Test
@@ -64,6 +87,7 @@ class DeviceActivityReporterTest {
6487 )
6588 empty.oneHour.total shouldBe 0
6689 empty.oneHour.versions shouldBe emptyList()
90+ empty.oneHour.buildFlavors shouldBe emptyList()
6791
6892 val report = DeviceActivityReporter .buildReport(
6993 devices = listOf (
@@ -81,6 +105,13 @@ class DeviceActivityReporterTest {
81105 percent = 100.0 ,
82106 )
83107 )
108+ report.oneHour.buildFlavors shouldBe listOf (
109+ DeviceActivityReporter .BuildFlavorStats (
110+ flavor = " <unknown>" ,
111+ count = 2 ,
112+ percent = 100.0 ,
113+ )
114+ )
84115 }
85116
86117 @Test
@@ -121,10 +152,23 @@ class DeviceActivityReporterTest {
121152 sanitized.endsWith(" ..." ) shouldBe true
122153 }
123154
155+ @Test
156+ fun `build flavor is parsed from user-agent style versions` () {
157+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/FOSS" ) shouldBe " FOSS"
158+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/gplay/dev-a1b2c3d" ) shouldBe " GPLAY"
159+ DeviceActivityReporter .buildFlavorForLog(" octi/1.2.3/GPLATE" ) shouldBe " GPLAY"
160+ DeviceActivityReporter .buildFlavorForLog(" 1.2.3" ) shouldBe " <unknown>"
161+ DeviceActivityReporter .buildFlavorForLog(null ) shouldBe " <unknown>"
162+ }
163+
124164 private fun DeviceActivityReporter.WindowStats.versionCounts (): Map <String , Int > {
125165 return versions.associate { it.version to it.count }
126166 }
127167
168+ private fun DeviceActivityReporter.WindowStats.buildFlavorCounts (): Map <String , Int > {
169+ return buildFlavors.associate { it.flavor to it.count }
170+ }
171+
128172 private fun device (
129173 version : String? ,
130174 lastSeen : Instant ,
0 commit comments