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

Function TestGetUsers_IncludeSystem

coderd/database/querier_test.go:2284–2338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2282}
2283
2284func TestGetUsers_IncludeSystem(t *testing.T) {
2285 t.Parallel()
2286
2287 tests := []struct {
2288 name string
2289 includeSystem bool
2290 wantSystemUser bool
2291 }{
2292 {
2293 name: "include system users",
2294 includeSystem: true,
2295 wantSystemUser: true,
2296 },
2297 {
2298 name: "exclude system users",
2299 includeSystem: false,
2300 wantSystemUser: false,
2301 },
2302 }
2303
2304 for _, tt := range tests {
2305 t.Run(tt.name, func(t *testing.T) {
2306 t.Parallel()
2307
2308 ctx := testutil.Context(t, testutil.WaitLong)
2309
2310 // Given: a system user
2311 // postgres: introduced by migration coderd/database/migrations/00030*_system_user.up.sql
2312 db, _ := dbtestutil.NewDB(t)
2313 other := dbgen.User(t, db, database.User{})
2314 users, err := db.GetUsers(ctx, database.GetUsersParams{
2315 IncludeSystem: tt.includeSystem,
2316 })
2317 require.NoError(t, err)
2318
2319 // Should always find the regular user
2320 foundRegularUser := false
2321 foundSystemUser := false
2322
2323 for _, u := range users {
2324 if u.IsSystem {
2325 foundSystemUser = true
2326 require.Equal(t, database.PrebuildsSystemUserID, u.ID)
2327 } else {
2328 foundRegularUser = true
2329 require.Equalf(t, other.ID.String(), u.ID.String(), "found unexpected regular user")
2330 }
2331 }
2332
2333 require.True(t, foundRegularUser, "regular user should always be found")
2334 require.Equal(t, tt.wantSystemUser, foundSystemUser, "system user presence should match includeSystem setting")
2335 require.Equal(t, tt.wantSystemUser, len(users) == 2, "should have 2 users when including system user, 1 otherwise")
2336 })
2337 }
2338}
2339
2340func TestUpdateSystemUser(t *testing.T) {
2341 t.Parallel()

Callers

nothing calls this directly

Calls 7

ContextFunction · 0.92
NewDBFunction · 0.92
UserFunction · 0.92
RunMethod · 0.65
GetUsersMethod · 0.65
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected