GoAT Site is library that implements Standard.site in Go.
atprotocol standard-site atproto library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

style(test): move common functions in lexicons_test

authored by

Anhgelus Morhtuuzh and committed by tangled.org e51b5386 872d304f

+84 -73
+84
lexicons_test.go
··· 1 + package site_test 2 + 3 + import ( 4 + "context" 5 + "strings" 6 + "testing" 7 + 8 + "github.com/bluesky-social/indigo/atproto/atclient" 9 + "github.com/bluesky-social/indigo/atproto/identity" 10 + "github.com/bluesky-social/indigo/atproto/syntax" 11 + "pgregory.net/rapid" 12 + site "tangled.org/anhgelus.world/goat-site" 13 + ) 14 + 15 + var rapidLowerRunes = rapid.RuneFrom([]rune("abcdefghijklmnopqrstuvwxyz")) 16 + 17 + func genBlob(t *rapid.T, baseMime string) (*site.Blob, map[string]any) { 18 + blob := &site.Blob{ 19 + CID: rapid.StringN(2, -1, 128).Draw(t, "blob_cid"), 20 + MimeType: baseMime + "/" + 21 + rapid.StringOfN(rapidLowerRunes, 2, 20, -1).Draw(t, "blob_mimeType"), 22 + Size: rapid.UintMin(1).Draw(t, "blob_size"), 23 + } 24 + return blob, map[string]any{ 25 + "$type": blob.Type(), 26 + "ref": map[string]any{"$link": blob.CID}, 27 + "mimeType": blob.MimeType, 28 + "size": blob.Size, 29 + } 30 + } 31 + 32 + func genURL(t *rapid.T) string { 33 + scheme := "http" 34 + if rapid.Bool().Draw(t, "url_secure?") { 35 + scheme += "s" 36 + } 37 + valid := rapid.RuneFrom([]rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")) 38 + base := rapid.StringOfN(rapidLowerRunes, 1, -1, 64).Draw(t, "url_base") 39 + tld := rapid.StringOfN(rapidLowerRunes, 2, -1, 10).Draw(t, "url_tld") 40 + sub := rapid.StringOfN(rapidLowerRunes, -1, -1, 32).Draw(t, "url_sub") 41 + var sb strings.Builder 42 + sb.Grow(len(base) + len(tld) + len(sub) + len(scheme) + 5) 43 + sb.WriteString(scheme) 44 + sb.WriteString("://") 45 + if sub != "" { 46 + sb.WriteString(sub) 47 + sb.WriteRune('.') 48 + } 49 + sb.WriteString(base) 50 + sb.WriteRune('.') 51 + sb.WriteString(tld) 52 + path := rapid.StringOfN(valid, -1, -1, 64).Draw(t, "url_path") 53 + if path != "" { 54 + sb.Grow(len(path) + 1) 55 + sb.WriteRune('/') 56 + sb.WriteString(path) 57 + } 58 + return sb.String() 59 + } 60 + 61 + func getClient(t *testing.T, test string, uri *syntax.ATURI, client **atclient.APIClient) (syntax.ATURI, *atclient.APIClient) { 62 + var err error 63 + defer func() { 64 + if err == nil { 65 + t.Log(uri.Authority().String(), uri.RecordKey()) 66 + } 67 + }() 68 + if *client != nil { 69 + return *uri, *client 70 + } 71 + dir := identity.DefaultDirectory() 72 + *uri, err = syntax.ParseATURI(test) 73 + if err != nil { 74 + t.Fatal(err) 75 + } 76 + var id *identity.Identity 77 + id, err = dir.Lookup(context.Background(), uri.Authority()) 78 + if err != nil { 79 + t.Fatal(err) 80 + } 81 + t.Log("using", id.PDSEndpoint(), "for", test) 82 + *client = atclient.NewAPIClient(id.PDSEndpoint()) 83 + return *uri, *client 84 + }
-73
publication_test.go
··· 3 3 import ( 4 4 "context" 5 5 "encoding/json" 6 - "strings" 7 6 "testing" 8 7 9 8 "github.com/bluesky-social/indigo/atproto/atclient" 10 - "github.com/bluesky-social/indigo/atproto/identity" 11 9 "github.com/bluesky-social/indigo/atproto/syntax" 12 10 "pgregory.net/rapid" 13 11 site "tangled.org/anhgelus.world/goat-site" ··· 37 35 } 38 36 } 39 37 40 - var rapidLowerRunes = rapid.RuneFrom([]rune("abcdefghijklmnopqrstuvwxyz")) 41 - 42 - func genBlob(t *rapid.T, baseMime string) (*site.Blob, map[string]any) { 43 - blob := &site.Blob{ 44 - CID: rapid.StringN(2, -1, 128).Draw(t, "blob_cid"), 45 - MimeType: baseMime + "/" + 46 - rapid.StringOfN(rapidLowerRunes, 2, 20, -1).Draw(t, "blob_mimeType"), 47 - Size: rapid.UintMin(1).Draw(t, "blob_size"), 48 - } 49 - return blob, map[string]any{ 50 - "$type": blob.Type(), 51 - "ref": map[string]any{"$link": blob.CID}, 52 - "mimeType": blob.MimeType, 53 - "size": blob.Size, 54 - } 55 - } 56 - 57 - func genURL(t *rapid.T) string { 58 - scheme := "http" 59 - if rapid.Bool().Draw(t, "url_secure?") { 60 - scheme += "s" 61 - } 62 - valid := rapid.RuneFrom([]rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")) 63 - base := rapid.StringOfN(rapidLowerRunes, 1, -1, 64).Draw(t, "url_base") 64 - tld := rapid.StringOfN(rapidLowerRunes, 2, -1, 10).Draw(t, "url_tld") 65 - sub := rapid.StringOfN(rapidLowerRunes, -1, -1, 32).Draw(t, "url_sub") 66 - var sb strings.Builder 67 - sb.Grow(len(base) + len(tld) + len(sub) + len(scheme) + 5) 68 - sb.WriteString(scheme) 69 - sb.WriteString("://") 70 - if sub != "" { 71 - sb.WriteString(sub) 72 - sb.WriteRune('.') 73 - } 74 - sb.WriteString(base) 75 - sb.WriteRune('.') 76 - sb.WriteString(tld) 77 - path := rapid.StringOfN(valid, -1, -1, 64).Draw(t, "url_path") 78 - if path != "" { 79 - sb.Grow(len(path) + 1) 80 - sb.WriteRune('/') 81 - sb.WriteString(path) 82 - } 83 - return sb.String() 84 - } 85 - 86 38 func TestPublication_JSON(t *testing.T) { 87 39 rapid.Check(t, func(t *rapid.T) { 88 40 theme, themeRaw := genBasicTheme(t) ··· 162 114 pubURI syntax.ATURI 163 115 pubClient *atclient.APIClient 164 116 ) 165 - 166 - func getClient(t *testing.T, test string, uri *syntax.ATURI, client **atclient.APIClient) (syntax.ATURI, *atclient.APIClient) { 167 - var err error 168 - defer func() { 169 - if err == nil { 170 - t.Log(uri.Authority().String(), uri.RecordKey()) 171 - } 172 - }() 173 - if *client != nil { 174 - return *uri, *client 175 - } 176 - dir := identity.DefaultDirectory() 177 - *uri, err = syntax.ParseATURI(test) 178 - if err != nil { 179 - t.Fatal(err) 180 - } 181 - var id *identity.Identity 182 - id, err = dir.Lookup(context.Background(), uri.Authority()) 183 - if err != nil { 184 - t.Fatal(err) 185 - } 186 - t.Log("using", id.PDSEndpoint(), "for", test) 187 - *client = atclient.NewAPIClient(id.PDSEndpoint()) 188 - return *uri, *client 189 - } 190 117 191 118 func TestGetPublication(t *testing.T) { 192 119 if testing.Short() {