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

Function assertConnectionReport

agent/agent_test.go:4200–4230  ·  view source on GitHub ↗
(t testing.TB, agentClient *agenttest.Client, connectionType proto.Connection_Type, status int, reason string)

Source from the content-addressed store, hash-verified

4198}
4199
4200func assertConnectionReport(t testing.TB, agentClient *agenttest.Client, connectionType proto.Connection_Type, status int, reason string) {
4201 t.Helper()
4202
4203 var reports []*proto.ReportConnectionRequest
4204 if !assert.Eventually(t, func() bool {
4205 reports = agentClient.GetConnectionReports()
4206 return len(reports) >= 2
4207 }, testutil.WaitMedium, testutil.IntervalFast, "waiting for 2 connection reports or more; got %d", len(reports)) {
4208 return
4209 }
4210
4211 assert.Len(t, reports, 2, "want 2 connection reports")
4212
4213 assert.Equal(t, proto.Connection_CONNECT, reports[0].GetConnection().GetAction(), "first report should be connect")
4214 assert.Equal(t, proto.Connection_DISCONNECT, reports[1].GetConnection().GetAction(), "second report should be disconnect")
4215 assert.Equal(t, connectionType, reports[0].GetConnection().GetType(), "connect type should be %s", connectionType)
4216 assert.Equal(t, connectionType, reports[1].GetConnection().GetType(), "disconnect type should be %s", connectionType)
4217 t1 := reports[0].GetConnection().GetTimestamp().AsTime()
4218 t2 := reports[1].GetConnection().GetTimestamp().AsTime()
4219 assert.True(t, t1.Before(t2) || t1.Equal(t2), "connect timestamp should be before or equal to disconnect timestamp")
4220 assert.NotEmpty(t, reports[0].GetConnection().GetIp(), "connect ip should not be empty")
4221 assert.NotEmpty(t, reports[1].GetConnection().GetIp(), "disconnect ip should not be empty")
4222 assert.Equal(t, 0, int(reports[0].GetConnection().GetStatusCode()), "connect status code should be 0")
4223 assert.Equal(t, status, int(reports[1].GetConnection().GetStatusCode()), "disconnect status code should be %d", status)
4224 assert.Equal(t, "", reports[0].GetConnection().GetReason(), "connect reason should be empty")
4225 if reason != "" {
4226 assert.Contains(t, reports[1].GetConnection().GetReason(), reason, "disconnect reason should contain %s", reason)
4227 } else {
4228 t.Logf("connection report disconnect reason: %s", reports[1].GetConnection().GetReason())
4229 }
4230}

Callers 5

TestAgent_Stats_MagicFunction · 0.85
TestAgent_SFTPFunction · 0.85
TestAgent_SCPFunction · 0.85

Calls 14

GetConnectionMethod · 0.80
GetTimestampMethod · 0.80
NotEmptyMethod · 0.80
GetIpMethod · 0.80
GetStatusCodeMethod · 0.80
HelperMethod · 0.65
LogfMethod · 0.65
GetConnectionReportsMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45
GetActionMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected