35 lines
835 B
Go
35 lines
835 B
Go
package asses
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"show-rss/src/db"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLast(t *testing.T) {
|
|
ctx := db.Test(t, context.Background())
|
|
|
|
if last, err := checkLast(ctx, "p"); err != nil {
|
|
t.Fatal(err)
|
|
} else if !last.T.IsZero() || last.Cksum != "" {
|
|
t.Fatal(last)
|
|
}
|
|
|
|
modtime := time.Now().Add(-5 * time.Minute)
|
|
if err := checked(ctx, "p", "cksum", modtime); err != nil {
|
|
t.Fatal(err)
|
|
} else if err := checked(ctx, "p", "cksum", modtime); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if last, err := checkLast(ctx, "p"); err != nil {
|
|
t.Fatal(err)
|
|
} else if last.T.IsZero() || last.Cksum != "cksum" {
|
|
t.Fatal(last)
|
|
} else if math.Abs(float64(last.Modified.Sub(modtime))) > float64(time.Second) {
|
|
t.Fatalf("modified not uploaded: %v vs. %v (diff of %v)", last.Modified, modtime, last.Modified.Sub(modtime))
|
|
}
|
|
}
|