diff options
| author | Xe <me@christine.website> | 2022-11-21 08:34:21 -0500 |
|---|---|---|
| committer | Xe <me@christine.website> | 2022-11-21 08:34:30 -0500 |
| commit | d4cde2dca21c09ecfa7392661574dc92200dd79e (patch) | |
| tree | 48e8f3bad6bea04c8e53939bffbfafbc05d62b54 /web/nodeinfo/nodeinfo_test.go | |
| parent | 2e2b6fa099a463666396b80048cb23af0e5a8fd9 (diff) | |
| download | x-d4cde2dca21c09ecfa7392661574dc92200dd79e.tar.xz x-d4cde2dca21c09ecfa7392661574dc92200dd79e.zip | |
web: add nodeinfo package to read nodeinfo metadata
Signed-off-by: Xe <me@christine.website>
Diffstat (limited to 'web/nodeinfo/nodeinfo_test.go')
| -rw-r--r-- | web/nodeinfo/nodeinfo_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/web/nodeinfo/nodeinfo_test.go b/web/nodeinfo/nodeinfo_test.go new file mode 100644 index 0000000..3241142 --- /dev/null +++ b/web/nodeinfo/nodeinfo_test.go @@ -0,0 +1,37 @@ +package nodeinfo + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "testing" + "time" +) + +const nodeInfo2point0 = `{"version":"2.0","software":{"name":"mastodon","version":"4.0.2"},"protocols":["activitypub"],"services":{"outbound":[],"inbound":[]},"usage":{"users":{"total":255,"activeMonth":163,"activeHalfyear":166},"localPosts":12107},"openRegistrations":true,"metadata":{}}` + +func TestNodeInfo(t *testing.T) { + mux := http.NewServeMux() + s := httptest.NewServer(mux) + mux.HandleFunc("/.well-known/nodeinfo", func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(wellKnownLinks{Links: []wellKnownLink{ + { + Rel: schema2point0, + Href: s.URL + "/nodeinfo/2.0", + }, + }}) + }) + mux.HandleFunc("/nodeinfo/2.0", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, nodeInfo2point0) + }) + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + _, err := FetchWithClient(ctx, s.Client(), s.URL) + if err != nil { + t.Fatal(err) + } +} |
