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

Function TestGenericInsights_RBAC

coderd/insights_test.go:2268–2385  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2266}
2267
2268func 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,

Callers

nothing calls this directly

Calls 13

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
UserLatencyInsightsMethod · 0.80
UserActivityInsightsMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected