| 1 | package tinyclient_test |
| 2 | |
| 3 | import ( |
| 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 | |
| 14 | type exampleBackend struct{} |
| 15 | |
| 16 | func (exampleBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) { |
| 17 | return nil, nil |
| 18 | } |
| 19 | func (exampleBackend) Policy() tinyclient.Policy { |
| 20 | return tinyclient.DefaultPolicy(strings.Repeat("a" , 64)) |
| 21 | } |
| 22 | func (exampleBackend) URL() string { return "http://relay.example" } |
| 23 | func (exampleBackend) Slug() string { return "standalone example" } |
| 24 | func (exampleBackend) Identity() string { return strings.Repeat("a" , 64) } |
| 25 | |
| 26 | func 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 | } |