Ported to RPC API from coderd/workspaceagents_test.go
(t *testing.T)
| 22 | |
| 23 | // Ported to RPC API from coderd/workspaceagents_test.go |
| 24 | func TestWorkspaceAgentReportStats(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | |
| 27 | for _, tc := range []struct { |
| 28 | name string |
| 29 | apiKeyScope rbac.ScopeName |
| 30 | }{ |
| 31 | { |
| 32 | name: "empty (backwards compat)", |
| 33 | apiKeyScope: "", |
| 34 | }, |
| 35 | { |
| 36 | name: "all", |
| 37 | apiKeyScope: rbac.ScopeAll, |
| 38 | }, |
| 39 | { |
| 40 | name: "no_user_data", |
| 41 | apiKeyScope: rbac.ScopeNoUserData, |
| 42 | }, |
| 43 | { |
| 44 | name: "application_connect", |
| 45 | apiKeyScope: rbac.ScopeApplicationConnect, |
| 46 | }, |
| 47 | } { |
| 48 | t.Run(tc.name, func(t *testing.T) { |
| 49 | t.Parallel() |
| 50 | |
| 51 | tickCh := make(chan time.Time) |
| 52 | flushCh := make(chan int, 1) |
| 53 | client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 54 | WorkspaceUsageTrackerFlush: flushCh, |
| 55 | WorkspaceUsageTrackerTick: tickCh, |
| 56 | }) |
| 57 | user := coderdtest.CreateFirstUser(t, client) |
| 58 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 59 | OrganizationID: user.OrganizationID, |
| 60 | OwnerID: user.UserID, |
| 61 | LastUsedAt: dbtime.Now().Add(-time.Minute), |
| 62 | }).WithAgent( |
| 63 | func(agent []*proto.Agent) []*proto.Agent { |
| 64 | for _, a := range agent { |
| 65 | a.ApiKeyScope = string(tc.apiKeyScope) |
| 66 | } |
| 67 | |
| 68 | return agent |
| 69 | }, |
| 70 | ).Do() |
| 71 | |
| 72 | ac := agentsdk.New(client.URL, agentsdk.WithFixedToken(r.AgentToken)) |
| 73 | conn, err := ac.ConnectRPC(context.Background()) |
| 74 | require.NoError(t, err) |
| 75 | defer func() { |
| 76 | _ = conn.Close() |
| 77 | }() |
| 78 | agentAPI := agentproto.NewDRPCAgentClient(conn) |
| 79 | |
| 80 | _, err = agentAPI.UpdateStats(context.Background(), &agentproto.UpdateStatsRequest{ |
| 81 | Stats: &agentproto.Stats{ |
nothing calls this directly
no test coverage detected