MCPcopy Create free account
hub / github.com/github/copilot-sdk / TestConnectionToken

Function TestConnectionToken

go/internal/e2e/connection_token_test.go:12–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestConnectionToken(t *testing.T) {
13 t.Run("explicit token round-trips successfully", func(t *testing.T) {
14 ctx := testharness.NewTestContext(t)
15 client := ctx.NewClient(func(opts *copilot.ClientOptions) {
16 opts.Connection = copilot.TCPConnection{
17 Path: ctx.CLIPath,
18 ConnectionToken: "right-token",
19 }
20 })
21 t.Cleanup(func() { client.ForceStop() })
22
23 if err := client.Start(t.Context()); err != nil {
24 t.Fatalf("Start failed: %v", err)
25 }
26
27 resp, err := client.Ping(t.Context(), "hi")
28 if err != nil {
29 t.Fatalf("Ping failed: %v", err)
30 }
31 if resp.Message != "pong: hi" {
32 t.Errorf("expected message 'pong: hi', got %q", resp.Message)
33 }
34 })
35
36 t.Run("auto-generated token round-trips successfully", func(t *testing.T) {
37 ctx := testharness.NewTestContext(t)
38 client := ctx.NewClient(func(opts *copilot.ClientOptions) {
39 opts.Connection = copilot.TCPConnection{Path: ctx.CLIPath}
40 })
41 t.Cleanup(func() { client.ForceStop() })
42
43 if err := client.Start(t.Context()); err != nil {
44 t.Fatalf("Start failed: %v", err)
45 }
46
47 resp, err := client.Ping(t.Context(), "hi")
48 if err != nil {
49 t.Fatalf("Ping failed: %v", err)
50 }
51 if resp.Message != "pong: hi" {
52 t.Errorf("expected message 'pong: hi', got %q", resp.Message)
53 }
54 })
55
56 t.Run("sibling client with wrong token is rejected", func(t *testing.T) {
57 ctx := testharness.NewTestContext(t)
58 good := ctx.NewClient(func(opts *copilot.ClientOptions) {
59 opts.Connection = copilot.TCPConnection{
60 Path: ctx.CLIPath,
61 ConnectionToken: "right-token",
62 }
63 })
64 t.Cleanup(func() { good.ForceStop() })
65
66 if err := good.Start(t.Context()); err != nil {
67 t.Fatalf("good client Start failed: %v", err)
68 }
69 port := good.RuntimePort()

Callers

nothing calls this directly

Calls 6

NewClientMethod · 0.95
ForceStopMethod · 0.95
StartMethod · 0.95
PingMethod · 0.95
RuntimePortMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…