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

Function TestExpectOne

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

Source from the content-addressed store, hash-verified

4657}
4658
4659func TestExpectOne(t *testing.T) {
4660 t.Parallel()
4661 if testing.Short() {
4662 t.SkipNow()
4663 }
4664
4665 t.Run("ErrNoRows", func(t *testing.T) {
4666 t.Parallel()
4667 sqlDB := testSQLDB(t)
4668 err := migrations.Up(sqlDB)
4669 require.NoError(t, err)
4670 db := database.New(sqlDB)
4671 ctx := context.Background()
4672
4673 _, err = database.ExpectOne(db.GetUsers(ctx, database.GetUsersParams{}))
4674 require.ErrorIs(t, err, sql.ErrNoRows)
4675 })
4676
4677 t.Run("TooMany", func(t *testing.T) {
4678 t.Parallel()
4679 sqlDB := testSQLDB(t)
4680 err := migrations.Up(sqlDB)
4681 require.NoError(t, err)
4682 db := database.New(sqlDB)
4683 ctx := context.Background()
4684
4685 // Create 2 organizations so the query returns >1
4686 dbgen.Organization(t, db, database.Organization{})
4687 dbgen.Organization(t, db, database.Organization{})
4688
4689 // Organizations is an easy table without foreign key dependencies
4690 _, err = database.ExpectOne(db.GetOrganizations(ctx, database.GetOrganizationsParams{}))
4691 require.ErrorContains(t, err, "too many rows returned")
4692 })
4693}
4694
4695func TestGetProvisionerJobsByIDsWithQueuePosition(t *testing.T) {
4696 t.Parallel()

Callers

nothing calls this directly

Calls 9

UpFunction · 0.92
NewFunction · 0.92
ExpectOneFunction · 0.92
OrganizationFunction · 0.92
SkipNowMethod · 0.80
testSQLDBFunction · 0.70
RunMethod · 0.65
GetUsersMethod · 0.65
GetOrganizationsMethod · 0.65

Tested by

no test coverage detected