MCPcopy Index your code
hub / github.com/coder/coder / TestReportConnectionEmpty

Function TestReportConnectionEmpty

agent/agent_internal_test.go:34–61  ·  view source on GitHub ↗

TestReportConnectionEmpty tests that reportConnection() doesn't choke if given an empty IP string, which is what we send if we cannot get the remote address.

(t *testing.T)

Source from the content-addressed store, hash-verified

32// TestReportConnectionEmpty tests that reportConnection() doesn't choke if given an empty IP string, which is what we
33// send if we cannot get the remote address.
34func TestReportConnectionEmpty(t *testing.T) {
35 t.Parallel()
36 connID := uuid.UUID{1}
37 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
38 ctx := testutil.Context(t, testutil.WaitShort)
39
40 uut := &agent{
41 hardCtx: ctx,
42 logger: logger,
43 }
44 disconnected := uut.reportConnection(connID, proto.Connection_TYPE_UNSPECIFIED, "")
45
46 require.Len(t, uut.reportConnections, 1)
47 req0 := uut.reportConnections[0]
48 require.Equal(t, proto.Connection_TYPE_UNSPECIFIED, req0.GetConnection().GetType())
49 require.Equal(t, "", req0.GetConnection().Ip)
50 require.Equal(t, connID[:], req0.GetConnection().GetId())
51 require.Equal(t, proto.Connection_CONNECT, req0.GetConnection().GetAction())
52
53 disconnected(0, "because")
54 require.Len(t, uut.reportConnections, 2)
55 req1 := uut.reportConnections[1]
56 require.Equal(t, proto.Connection_TYPE_UNSPECIFIED, req1.GetConnection().GetType())
57 require.Equal(t, "", req1.GetConnection().Ip)
58 require.Equal(t, connID[:], req1.GetConnection().GetId())
59 require.Equal(t, proto.Connection_DISCONNECT, req1.GetConnection().GetAction())
60 require.Equal(t, "because", req1.GetConnection().GetReason())
61}
62
63func TestContextConfigAPI_InitOnce(t *testing.T) {
64 t.Parallel()

Callers

nothing calls this directly

Calls 9

reportConnectionMethod · 0.95
ContextFunction · 0.92
GetConnectionMethod · 0.80
LenMethod · 0.45
EqualMethod · 0.45
GetTypeMethod · 0.45
GetIdMethod · 0.45
GetActionMethod · 0.45
GetReasonMethod · 0.45

Tested by

no test coverage detected