From d4cde2dca21c09ecfa7392661574dc92200dd79e Mon Sep 17 00:00:00 2001 From: Xe Date: Mon, 21 Nov 2022 08:34:21 -0500 Subject: web: add nodeinfo package to read nodeinfo metadata Signed-off-by: Xe --- web/nodeinfo/nodeinfo_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 web/nodeinfo/nodeinfo_test.go (limited to 'web/nodeinfo/nodeinfo_test.go') 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) + } +} -- cgit v1.2.3