fix(stats): elect trusted mileage source
This commit is contained in:
40
go/vehicle-gateway/cmd/stats-backfill/main_test.go
Normal file
40
go/vehicle-gateway/cmd/stats-backfill/main_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestChooseTrustedSourceKeepsContinuingSourceAndRejectsNewJump(t *testing.T) {
|
||||
previous := []dailySourceLast{{
|
||||
VIN: "LA9GG64L7PBAF4001",
|
||||
SourceKey: normalizedSourceKey("13307765812", "115.231.168.135:42630"),
|
||||
Phone: "13307765812",
|
||||
SourceEndpoint: "115.231.168.135:42630",
|
||||
TotalKM: 4100.8,
|
||||
}}
|
||||
current := []dailySourceLast{
|
||||
{
|
||||
VIN: "LA9GG64L7PBAF4001",
|
||||
SourceKey: normalizedSourceKey("13307765812", "115.159.85.149:28316"),
|
||||
Phone: "13307765812",
|
||||
SourceEndpoint: "115.159.85.149:28316",
|
||||
TotalKM: 42447.2,
|
||||
},
|
||||
{
|
||||
VIN: "LA9GG64L7PBAF4001",
|
||||
SourceKey: normalizedSourceKey("13307765812", "115.231.168.135:20215"),
|
||||
Phone: "13307765812",
|
||||
SourceEndpoint: "115.231.168.135:20215",
|
||||
TotalKM: 4123.9,
|
||||
},
|
||||
}
|
||||
|
||||
chosen, ok := chooseTrustedSource(current, previous)
|
||||
if !ok {
|
||||
t.Fatal("chooseTrustedSource() did not choose a source")
|
||||
}
|
||||
if chosen.current.SourceKey != normalizedSourceKey("13307765812", "115.231.168.135:20215") {
|
||||
t.Fatalf("chosen source = %q", chosen.current.SourceKey)
|
||||
}
|
||||
if delta := chosen.current.TotalKM - chosen.previous.TotalKM; delta < 23 || delta > 24 {
|
||||
t.Fatalf("delta = %v, want about 23.1", delta)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user