tinyrelayfile
tinyrelay/tinyclient/public_test.go/

tinyclient/public_test.go raw
1package tinyclient_test
2
3import (
4 "context"
5 "encoding/json"
6 "net/http"
7 "net/http/httptest"
8 "strings"
9 "testing"
10
11 "github.com/FelineStateMachine/tinyrelay/tinyclient"
12)
13
14type exampleBackend struct{}
15
16func (exampleBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) {
17 return nil, nil
18}
19func (exampleBackend) Policy() tinyclient.Policy {
20 return tinyclient.DefaultPolicy(strings.Repeat("a", 64))
21}
22func (exampleBackend) URL() string { return "http://relay.example" }
23func (exampleBackend) Slug() string { return "standalone example" }
24func (exampleBackend) Identity() string { return strings.Repeat("a", 64) }
25
26func TestPublicBackendRendersWithoutInternalImports(t *testing.T) {
27 app, err := tinyclient.New(exampleBackend{}, tinyclient.Options{})
28 if err != nil {
29 t.Fatal(err)
30 }
31 response := httptest.NewRecorder()
32 app.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/", nil))
33 if response.Code != http.StatusOK || !strings.Contains(response.Body.String(), "standalone example") || !strings.Contains(response.Body.String(), "<html") {
34 t.Fatalf("render: %d %s", response.Code, response.Body.String())
35 }
36}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs