(t *testing.T)
| 2266 | } |
| 2267 | |
| 2268 | func TestGenericInsights_RBAC(t *testing.T) { |
| 2269 | t.Parallel() |
| 2270 | |
| 2271 | y, m, d := time.Now().UTC().Date() |
| 2272 | today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC) |
| 2273 | |
| 2274 | type fetchInsightsFunc func(ctx context.Context, client *codersdk.Client, startTime, endTime time.Time, templateIDs ...uuid.UUID) error |
| 2275 | |
| 2276 | type test struct { |
| 2277 | withTemplate bool |
| 2278 | } |
| 2279 | |
| 2280 | endpoints := map[string]fetchInsightsFunc{ |
| 2281 | "UserLatency": func(ctx context.Context, client *codersdk.Client, startTime, endTime time.Time, templateIDs ...uuid.UUID) error { |
| 2282 | _, err := client.UserLatencyInsights(ctx, codersdk.UserLatencyInsightsRequest{ |
| 2283 | StartTime: startTime, |
| 2284 | EndTime: endTime, |
| 2285 | TemplateIDs: templateIDs, |
| 2286 | }) |
| 2287 | return err |
| 2288 | }, |
| 2289 | "UserActivity": func(ctx context.Context, client *codersdk.Client, startTime, endTime time.Time, templateIDs ...uuid.UUID) error { |
| 2290 | _, err := client.UserActivityInsights(ctx, codersdk.UserActivityInsightsRequest{ |
| 2291 | StartTime: startTime, |
| 2292 | EndTime: endTime, |
| 2293 | TemplateIDs: templateIDs, |
| 2294 | }) |
| 2295 | return err |
| 2296 | }, |
| 2297 | } |
| 2298 | |
| 2299 | for endpointName, endpoint := range endpoints { |
| 2300 | t.Run(fmt.Sprintf("With%sEndpoint", endpointName), func(t *testing.T) { |
| 2301 | t.Parallel() |
| 2302 | |
| 2303 | tests := []test{ |
| 2304 | {true}, |
| 2305 | {false}, |
| 2306 | } |
| 2307 | |
| 2308 | for _, tt := range tests { |
| 2309 | t.Run("AsOwner", func(t *testing.T) { |
| 2310 | t.Parallel() |
| 2311 | |
| 2312 | client := coderdtest.New(t, nil) |
| 2313 | owner := coderdtest.CreateFirstUser(t, client) |
| 2314 | |
| 2315 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 2316 | defer cancel() |
| 2317 | |
| 2318 | var templateIDs []uuid.UUID |
| 2319 | if tt.withTemplate { |
| 2320 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 2321 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
| 2322 | templateIDs = append(templateIDs, template.ID) |
| 2323 | } |
| 2324 | |
| 2325 | err := endpoint(ctx, client, |
nothing calls this directly
no test coverage detected