The importer from t5de-hub's docs/imports.md: says hello to the hub with its key pair, follows the console's config (paused, rate, jobs at a time, IMVU accounts, whose sealed passwords it keeps), claims jobs, finds each product's newest revision on IMVU's CDN, converts it (originals for placeholders, no _contents.json, ProductRating from IMVU's rating), checks it by t5de-api's pack rules and uploads it to the catalog with an import token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package imvu_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.t5de.dev/t5de/t5de-importer/internal/imvu"
|
|
"git.t5de.dev/t5de/t5de-importer/internal/imvutest"
|
|
)
|
|
|
|
func TestLatest(t *testing.T) {
|
|
cdn := imvutest.New(t)
|
|
for _, rev := range []int{1, 2, 3, 5} { // 4 missing: a gap shorter than Misses is crossed
|
|
cdn.Add(7, rev, imvutest.File{Name: "index.xml", Data: imvutest.Index(1)})
|
|
}
|
|
c := &imvu.CDN{URL: cdn.URL, Limiter: imvu.NewLimiter(1000)}
|
|
ctx := context.Background()
|
|
for _, tc := range []struct{ from, latest, probes int }{{0, 5, 8}, {1, 5, 8}, {4, 5, 5}, {6, 0, 3}} {
|
|
latest, probes, err := c.Latest(ctx, 7, tc.from)
|
|
if err != nil || latest != tc.latest || probes != tc.probes {
|
|
t.Errorf("from %d: latest %d, %d probes, %v; want %d, %d", tc.from, latest, probes, err, tc.latest, tc.probes)
|
|
}
|
|
}
|
|
if _, err := c.CFL(ctx, 7, 4); !errors.Is(err, imvu.ErrMissing) {
|
|
t.Errorf("missing revision: %v", err)
|
|
}
|
|
if _, err := c.File(ctx, 7, 1, "../../8/1"); err == nil {
|
|
t.Error("a file outside the revision: no error")
|
|
}
|
|
}
|
|
|
|
func TestLimiter(t *testing.T) {
|
|
l := imvu.NewLimiter(50) // 20 ms apart
|
|
start := time.Now()
|
|
for range 6 {
|
|
if err := l.Wait(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if d := time.Since(start); d < 90*time.Millisecond {
|
|
t.Errorf("6 requests at 50 a second took %s", d)
|
|
}
|
|
l.SetRate(0.001) // a minute apart
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
|
|
defer cancel()
|
|
l.Wait(ctx) // the next turn is ~20 ms away
|
|
if err := l.Wait(ctx); err == nil {
|
|
t.Error("waited a minute within 20 ms")
|
|
}
|
|
}
|