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

Function TestBatchUpdateMetadata

coderd/agentapi/metadata_test.go:25–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestBatchUpdateMetadata(t *testing.T) {
26 t.Parallel()
27
28 agent := database.WorkspaceAgent{
29 ID: uuid.New(),
30 }
31
32 t.Run("OK", func(t *testing.T) {
33 t.Parallel()
34
35 ctx := testutil.Context(t, testutil.WaitShort)
36
37 ctrl := gomock.NewController(t)
38 store := dbmock.NewMockStore(ctrl)
39 ps := pubsub.NewInMemory()
40 reg := prometheus.NewRegistry()
41
42 now := dbtime.Now()
43 req := &agentproto.BatchUpdateMetadataRequest{
44 Metadata: []*agentproto.Metadata{
45 {
46 Key: "awesome key",
47 Result: &agentproto.WorkspaceAgentMetadata_Result{
48 CollectedAt: timestamppb.New(now.Add(-10 * time.Second)),
49 Age: 10,
50 Value: "awesome value",
51 Error: "",
52 },
53 },
54 {
55 Key: "uncool key",
56 Result: &agentproto.WorkspaceAgentMetadata_Result{
57 CollectedAt: timestamppb.New(now.Add(-3 * time.Second)),
58 Age: 3,
59 Value: "",
60 Error: "\t uncool error ",
61 },
62 },
63 },
64 }
65 batchSize := len(req.Metadata)
66 // This test sends 2 metadata entries (one clean, one with
67 // whitespace padding). With batch size 2 we expect exactly
68 // 1 capacity flush. The matcher verifies that stored values
69 // are trimmed while clean values pass through unchanged.
70 expectedValues := map[string]string{
71 "awesome key": "awesome value",
72 "uncool key": "",
73 }
74 expectedErrors := map[string]string{
75 "awesome key": "",
76 "uncool key": "uncool error",
77 }
78 store.EXPECT().
79 BatchUpdateWorkspaceAgentMetadata(
80 gomock.Any(),
81 gomock.Cond(func(arg database.BatchUpdateWorkspaceAgentMetadataParams) bool {
82 if len(arg.Key) != len(expectedValues) {

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
BatchUpdateMetadataMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
NewInMemoryFunction · 0.92
NowFunction · 0.92
NewBatcherFunction · 0.92
WithLoggerFunction · 0.92
LoggerFunction · 0.92
WithBatchSizeFunction · 0.92
EventuallyFunction · 0.92
NewMethod · 0.65

Tested by

no test coverage detected