oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1package callstest
2
3import (
4 "strings"
5 "testing"
6 "time"
7)
8
9// Spec §15.28: every roster names what each peer's participation was
10// opened from — an app's own "<app> <version>" header, "native" for an
11// app from before it (the Go HTTP client's agent and no header), nothing
12// for a browser — and the `peer` event that admits a newcomer carries it.
13func TestRosterNamesEachPeersClient(t *testing.T) {
14 for _, c := range []struct {
15 name string
16 headers map[string]string
17 want string // the roster's client for Bob; "" is no key at all
18 }{
19 {"an app that says", map[string]string{"User-Agent": "Go-http-client/1.1", "X-Calls-Client": "mac 0.4.12"}, `"client":"mac 0.4.12"`},
20 {"an app from before", map[string]string{"User-Agent": "Go-http-client/1.1"}, `"client":"native"`},
21 {"a browser", nil, ""},
22 {"a header that is not one", map[string]string{"User-Agent": "Go-http-client/1.1", "X-Calls-Client": "mac <script>"}, ""},
23 } {
24 t.Run(c.name, func(t *testing.T) {
25 x, sqid, _ := memberWithMeeting(t)
26 a := x.browser(t)
27 a.signIn("paul@example.com")
28 sa := a.stream("/m/" + sqid + "/stream")
29 defer sa.close()
30 pa, _ := sa.hello()
31 a.signal(sqid, pa, `{"type":"join"}`)
32 sa.nextOf("roster", 2*time.Second)
33
34 b := newMemberBrowser(t, x, "paul@rslw.com")
35 b.streamHeaders = c.headers
36 sb := b.stream("/m/" + sqid + "/stream")
37 defer sb.close()
38 pb, _ := sb.hello()
39 b.signal(sqid, pb, `{"type":"join"}`)
40 _, roster, ok := sb.nextOf("roster", 2*time.Second)
41 if !ok {
42 t.Fatal("Bob got no roster")
43 }
44 _, peer, ok := sa.nextOf("peer", 2*time.Second)
45 if !ok {
46 t.Fatal("Paul was not told Bob arrived")
47 }
48 // Paul's stream is a browser's: no client key for him, ever.
49 if c.want == "" {
50 if strings.Contains(string(roster), `"client"`) || strings.Contains(string(peer), `"client"`) {
51 t.Fatalf("no client expected: roster %s, peer %s", roster, peer)
52 }
53 return
54 }
55 if strings.Count(string(roster), `"client"`) != 1 || !strings.Contains(string(roster), c.want) {
56 t.Fatalf("Bob's own roster entry should carry %s, and only it: %s", c.want, roster)
57 }
58 if !strings.Contains(string(peer), c.want) {
59 t.Fatalf("the peer event Paul gets should carry %s: %s", c.want, peer)
60 }
61 })
62 }
63}
64