a love letter to tangled (android, iOS, and a search API)
at main 86 lines 2.2 kB view raw
1package backfill 2 3import ( 4 "context" 5 "fmt" 6 "net/http" 7 "net/http/httptest" 8 "testing" 9) 10 11func TestRepoStatusNotFound(t *testing.T) { 12 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 13 if r.URL.Path != "/info/did:plc:missing" { 14 t.Fatalf("unexpected path: %s", r.URL.Path) 15 } 16 http.NotFound(w, r) 17 })) 18 defer ts.Close() 19 20 admin, err := NewHTTPTapAdmin(ts.URL+"/channel", "") 21 if err != nil { 22 t.Fatalf("new admin: %v", err) 23 } 24 25 status, err := admin.RepoStatus(context.Background(), "did:plc:missing") 26 if err != nil { 27 t.Fatalf("repo status: %v", err) 28 } 29 if status.Found { 30 t.Fatalf("expected found=false, got %#v", status) 31 } 32 if status.Tracked { 33 t.Fatalf("expected tracked=false for 404") 34 } 35} 36 37func TestRepoStatusParsesBackfillState(t *testing.T) { 38 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 39 if r.URL.Path != "/info/did:plc:abc" { 40 t.Fatalf("unexpected path: %s", r.URL.Path) 41 } 42 w.Header().Set("Content-Type", "application/json") 43 _, _ = fmt.Fprint(w, `{"tracked":true,"status":"backfilling"}`) 44 })) 45 defer ts.Close() 46 47 admin, err := NewHTTPTapAdmin(ts.URL+"/channel", "") 48 if err != nil { 49 t.Fatalf("new admin: %v", err) 50 } 51 52 status, err := admin.RepoStatus(context.Background(), "did:plc:abc") 53 if err != nil { 54 t.Fatalf("repo status: %v", err) 55 } 56 if !status.Found || !status.Tracked { 57 t.Fatalf("expected tracked found status, got %#v", status) 58 } 59 if !status.Backfilling { 60 t.Fatalf("expected backfilling=true, got %#v", status) 61 } 62 if status.Backfilled { 63 t.Fatalf("expected backfilled=false, got %#v", status) 64 } 65} 66 67func TestRepoStatusParsesExplicitTrackedFalse(t *testing.T) { 68 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { 69 w.Header().Set("Content-Type", "application/json") 70 _, _ = fmt.Fprint(w, `{"tracked":false}`) 71 })) 72 defer ts.Close() 73 74 admin, err := NewHTTPTapAdmin(ts.URL+"/channel", "") 75 if err != nil { 76 t.Fatalf("new admin: %v", err) 77 } 78 79 status, err := admin.RepoStatus(context.Background(), "did:plc:abc") 80 if err != nil { 81 t.Fatalf("repo status: %v", err) 82 } 83 if status.Tracked { 84 t.Fatalf("expected tracked=false, got %#v", status) 85 } 86}