41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|