fork of indigo with slightly nicer lexgen
1package testing
2
3import (
4 "testing"
5 "time"
6
7 "github.com/bluesky-social/indigo/fakedata"
8 "github.com/bluesky-social/indigo/util"
9 "github.com/bluesky-social/indigo/xrpc"
10
11 "github.com/stretchr/testify/assert"
12)
13
14const (
15 adminPassword = "admin"
16 celebCount = 2
17 regularCount = 5
18 maxPosts = 5
19 maxFollows = 5
20 // TODO: golang PDS does not support putRecord
21 maxMutes = 0 // 2
22 fracMention = 0.3
23 // TODO: golang PDS does not support images
24 genAvatar = false // true
25 genBanner = false // true
26 fracImage = 0.0 // 0.3
27)
28
29func genTestCatalog(t *testing.T, pdsHost string) fakedata.AccountCatalog {
30
31 ap := adminPassword
32 xrpccAdmin := xrpc.Client{
33 Client: util.TestingHTTPClient(),
34 Host: pdsHost,
35 }
36 xrpccAdmin.AdminToken = &ap
37
38 var catalog fakedata.AccountCatalog
39 for i := 0; i < celebCount; i++ {
40 usr, err := fakedata.GenAccount(&xrpccAdmin, i, "celebrity", "", nil)
41 if err != nil {
42 t.Fatal(err)
43 }
44 catalog.Celebs = append(catalog.Celebs, *usr)
45 }
46 for i := 0; i < regularCount; i++ {
47 usr, err := fakedata.GenAccount(&xrpccAdmin, i, "regular", "", nil)
48 if err != nil {
49 t.Fatal(err)
50 }
51 catalog.Regulars = append(catalog.Regulars, *usr)
52 }
53 return catalog
54}
55
56func TestPDSFakedata(t *testing.T) {
57 if testing.Short() {
58 t.Skip("skipping PDS+fakedata test in 'short' test mode")
59 }
60 assert := assert.New(t)
61 plcc := TestPLC(t)
62 pds := MustSetupPDS(t, ".test", plcc)
63 pds.Run(t)
64
65 time.Sleep(time.Millisecond * 50)
66
67 catalog := genTestCatalog(t, pds.HTTPHost())
68 combined := catalog.Combined()
69 testClient := util.TestingHTTPClient()
70
71 // generate profile, graph, posts
72 for _, acc := range combined {
73 xrpcc, err := fakedata.AccountXrpcClient(pds.HTTPHost(), &acc)
74 xrpcc.Client = testClient
75 if err != nil {
76 t.Fatal(err)
77 }
78 // TODO: golang PDS does not support putRecord
79 //assert.NoError(fakedata.GenProfile(xrpcc, &acc, genAvatar, genBanner))
80 assert.NoError(fakedata.GenFollowsAndMutes(xrpcc, &catalog, &acc, maxFollows, maxMutes))
81 assert.NoError(fakedata.GenPosts(xrpcc, &catalog, &acc, maxPosts, fracImage, fracMention))
82 }
83
84 // generate interactions (additional posts, etc)
85 for _, acc := range combined {
86 xrpcc, err := fakedata.AccountXrpcClient(pds.HTTPHost(), &acc)
87 xrpcc.Client = testClient
88 if err != nil {
89 t.Fatal(err)
90 }
91 assert.NoError(fakedata.GenFollowsAndMutes(xrpcc, &catalog, &acc, maxFollows, maxMutes))
92 assert.NoError(fakedata.GenPosts(xrpcc, &catalog, &acc, maxPosts, fracImage, fracMention))
93 }
94
95 // do browsing (read-only)
96 for _, acc := range combined {
97 xrpcc, err := fakedata.AccountXrpcClient(pds.HTTPHost(), &acc)
98 xrpcc.Client = testClient
99 if err != nil {
100 t.Fatal(err)
101 }
102 // TODO: golang listNotifications broken
103 //assert.NoError(fakedata.BrowseAccount(xrpcc, &acc))
104 }
105}