eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "encoding/json"
5 "net/http"
6 "strings"
7 "testing"
8)
9
10// The integrations catalog is public (like /api/apps): the embedded registry,
11// verbatim, so clients can render the connect catalog and the write ops'
12// consent lines.
13func TestIntegrationsEndpoint(t *testing.T) {
14 ts, _ := newTestServer(t)
15 resp, err := http.Get(ts.URL + "/api/integrations")
16 if err != nil {
17 t.Fatal(err)
18 }
19 defer resp.Body.Close()
20 if resp.StatusCode != http.StatusOK {
21 t.Fatalf("status %d", resp.StatusCode)
22 }
23 if ct := resp.Header.Get("Content-Type"); !strings.Contains(ct, "application/json") {
24 t.Fatalf("content-type %q", ct)
25 }
26 var out struct {
27 Schema int `json:"schema"`
28 Services []struct {
29 ID string `json:"id"`
30 Ops []struct {
31 ID string `json:"id"`
32 Access string `json:"access"`
33 Confirm string `json:"confirm"`
34 } `json:"ops"`
35 } `json:"services"`
36 }
37 if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
38 t.Fatal(err)
39 }
40 if out.Schema != 1 {
41 t.Errorf("schema = %d, want 1", out.Schema)
42 }
43 if len(out.Services) != 5 {
44 t.Fatalf("got %d services, want 5", len(out.Services))
45 }
46 // DNSimple carries a write op with its consent line — the shape the web
47 // catalog and consent chips depend on.
48 confirmedWrite := false
49 for _, svc := range out.Services {
50 if svc.ID != "dnsimple" {
51 continue
52 }
53 for _, op := range svc.Ops {
54 if op.Access == "write" && op.Confirm != "" {
55 confirmedWrite = true
56 }
57 }
58 }
59 if !confirmedWrite {
60 t.Fatal("dnsimple must expose a write op with a confirm line")
61 }
62}
63