diff --git a/db.go b/db.go index 3f9bf13..bd33fde 100644 --- a/db.go +++ b/db.go @@ -187,7 +187,7 @@ func (tdb *TelemDb) GetPackets(ctx context.Context, filter BusEventFilter, lim * sb.WriteString(strings.Join(whereFrags, " AND ")) } - sb.WriteString(" ORDER BY ts ASC") + sb.WriteString(" ORDER BY ts DESC") // Augment our data further if there's i.e a limit modifier. // TODO: factor this out maybe? @@ -270,7 +270,7 @@ func (tdb *TelemDb) GetValues(ctx context.Context, filter BusEventFilter, // join qstrings with AND sb.WriteString(strings.Join(whereFrags, " AND ")) - sb.WriteString(" ORDER BY ts ASC") + sb.WriteString(" ORDER BY ts DESC") if lim != nil { lim.ModifyStatement(&sb) diff --git a/http_test.go b/http_test.go index 12f2d77..c941ab0 100644 --- a/http_test.go +++ b/http_test.go @@ -203,9 +203,10 @@ func Test_ApiV1GetPackets(t *testing.T) { t.Fatalf("response length did not match, want %d got %d", len(tt.expectedResults), len(resultEvents)) } + // Note, the results are flipped here. We return earliest first. for idx := range tt.expectedResults { expected := tt.expectedResults[idx] - actual := resultEvents[idx] + actual := resultEvents[len(resultEvents) - 1 - idx] if !expected.Equals(&actual) { t.Errorf("packet did not match, want %v got %v", expected, actual) }