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

Function TestBatchCreateLogs

coderd/agentapi/logs_test.go:26–482  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestBatchCreateLogs(t *testing.T) {
27 t.Parallel()
28
29 var (
30 agent = database.WorkspaceAgent{
31 ID: uuid.New(),
32 }
33 logSource = database.WorkspaceAgentLogSource{
34 WorkspaceAgentID: agent.ID,
35 CreatedAt: dbtime.Now(),
36 ID: uuid.New(),
37 }
38 )
39
40 t.Run("OK", func(t *testing.T) {
41 t.Parallel()
42
43 dbM := dbmock.NewMockStore(gomock.NewController(t))
44
45 publishWorkspaceUpdateCalled := false
46 publishWorkspaceAgentLogsUpdateCalled := false
47 now := dbtime.Now()
48 api := &agentapi.LogsAPI{
49 AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
50 return agent, nil
51 },
52 Database: dbM,
53 Log: testutil.Logger(t),
54 PublishWorkspaceUpdateFn: func(ctx context.Context, _ uuid.UUID, kind wspubsub.WorkspaceEventKind) error {
55 publishWorkspaceUpdateCalled = true
56 return nil
57 },
58 PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
59 publishWorkspaceAgentLogsUpdateCalled = true
60
61 // Check the message content, should be for -1 since the lowest
62 // log we inserted was 0.
63 assert.Equal(t, agentsdk.LogsNotifyMessage{CreatedAfter: -1}, msg)
64 },
65 TimeNowFn: func() time.Time { return now },
66 }
67
68 req := &agentproto.BatchCreateLogsRequest{
69 LogSourceId: logSource.ID[:],
70 Logs: []*agentproto.Log{
71 {
72 CreatedAt: timestamppb.New(now),
73 Level: agentproto.Log_TRACE,
74 Output: "log line 1",
75 },
76 {
77 CreatedAt: timestamppb.New(now.Add(time.Hour)),
78 Level: agentproto.Log_DEBUG,
79 Output: "log line 2",
80 },
81 {
82 CreatedAt: timestamppb.New(now.Add(2 * time.Hour)),
83 Level: agentproto.Log_INFO,

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
BatchCreateLogsMethod · 0.95
NowFunction · 0.92
NewMockStoreFunction · 0.92
LoggerFunction · 0.92
LogLevelTypeAlias · 0.92
SanitizeLogOutputFunction · 0.92
NewMethod · 0.65
RunMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected