chore: Update sqlc to v1.16.0 (#5788)

* chore: Update sqlc to v1.16.0

* chore: Fix cases where types became Null-types

* chore: Set parameter_schemas default_destination_scheme and default_source_scheme to NOT NULL

* chore: Add enum validation to database fake

* chore: Fix all tests that skipping enum values

* fix: Use correct err in providionerdserver audit log failure log
This commit is contained in:
Mathias Fredriksson
2023-01-23 13:14:47 +02:00
committed by GitHub
parent f67acac2b7
commit 8afdf24d10
29 changed files with 1525 additions and 216 deletions
@@ -36,9 +36,10 @@ func TestActiveUsers(t *testing.T) {
Database: func() database.Store {
db := databasefake.New()
_, _ = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
UserID: uuid.New(),
LastUsed: database.Now(),
Scope: database.APIKeyScopeAll,
UserID: uuid.New(),
LastUsed: database.Now(),
LoginType: database.LoginTypePassword,
Scope: database.APIKeyScopeAll,
})
return db
},
@@ -48,16 +49,18 @@ func TestActiveUsers(t *testing.T) {
Database: func() database.Store {
db := databasefake.New()
_, _ = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
UserID: uuid.New(),
LastUsed: database.Now(),
Scope: database.APIKeyScopeAll,
UserID: uuid.New(),
LastUsed: database.Now(),
LoginType: database.LoginTypePassword,
Scope: database.APIKeyScopeAll,
})
// Because this API key hasn't been used in the past hour, this shouldn't
// add to the user count.
_, _ = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
UserID: uuid.New(),
LastUsed: database.Now().Add(-2 * time.Hour),
Scope: database.APIKeyScopeAll,
UserID: uuid.New(),
LastUsed: database.Now().Add(-2 * time.Hour),
LoginType: database.LoginTypePassword,
Scope: database.APIKeyScopeAll,
})
return db
},
@@ -67,14 +70,16 @@ func TestActiveUsers(t *testing.T) {
Database: func() database.Store {
db := databasefake.New()
_, _ = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
UserID: uuid.New(),
LastUsed: database.Now(),
Scope: database.APIKeyScopeAll,
UserID: uuid.New(),
LastUsed: database.Now(),
LoginType: database.LoginTypePassword,
Scope: database.APIKeyScopeAll,
})
_, _ = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
UserID: uuid.New(),
LastUsed: database.Now(),
Scope: database.APIKeyScopeAll,
UserID: uuid.New(),
LastUsed: database.Now(),
LoginType: database.LoginTypePassword,
Scope: database.APIKeyScopeAll,
})
return db
},
@@ -102,50 +107,59 @@ func TestWorkspaces(t *testing.T) {
t.Parallel()
insertRunning := func(db database.Store) database.ProvisionerJob {
job, _ := db.InsertProvisionerJob(context.Background(), database.InsertProvisionerJobParams{
ID: uuid.New(),
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Provisioner: database.ProvisionerTypeEcho,
job, err := db.InsertProvisionerJob(context.Background(), database.InsertProvisionerJobParams{
ID: uuid.New(),
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Provisioner: database.ProvisionerTypeEcho,
StorageMethod: database.ProvisionerStorageMethodFile,
Type: database.ProvisionerJobTypeWorkspaceBuild,
})
_, _ = db.InsertWorkspaceBuild(context.Background(), database.InsertWorkspaceBuildParams{
require.NoError(t, err)
_, err = db.InsertWorkspaceBuild(context.Background(), database.InsertWorkspaceBuildParams{
ID: uuid.New(),
WorkspaceID: uuid.New(),
JobID: job.ID,
BuildNumber: 1,
Transition: database.WorkspaceTransitionStart,
Reason: database.BuildReasonInitiator,
})
require.NoError(t, err)
// This marks the job as started.
_, _ = db.AcquireProvisionerJob(context.Background(), database.AcquireProvisionerJobParams{
_, err = db.AcquireProvisionerJob(context.Background(), database.AcquireProvisionerJobParams{
StartedAt: sql.NullTime{
Time: database.Now(),
Valid: true,
},
Types: []database.ProvisionerType{database.ProvisionerTypeEcho},
})
require.NoError(t, err)
return job
}
insertCanceled := func(db database.Store) {
job := insertRunning(db)
_ = db.UpdateProvisionerJobWithCancelByID(context.Background(), database.UpdateProvisionerJobWithCancelByIDParams{
err := db.UpdateProvisionerJobWithCancelByID(context.Background(), database.UpdateProvisionerJobWithCancelByIDParams{
ID: job.ID,
CanceledAt: sql.NullTime{
Time: database.Now(),
Valid: true,
},
})
_ = db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
require.NoError(t, err)
err = db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
ID: job.ID,
CompletedAt: sql.NullTime{
Time: database.Now(),
Valid: true,
},
})
require.NoError(t, err)
}
insertFailed := func(db database.Store) {
job := insertRunning(db)
_ = db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
err := db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
ID: job.ID,
CompletedAt: sql.NullTime{
Time: database.Now(),
@@ -156,17 +170,19 @@ func TestWorkspaces(t *testing.T) {
Valid: true,
},
})
require.NoError(t, err)
}
insertSuccess := func(db database.Store) {
job := insertRunning(db)
_ = db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
err := db.UpdateProvisionerJobWithCompleteByID(context.Background(), database.UpdateProvisionerJobWithCompleteByIDParams{
ID: job.ID,
CompletedAt: sql.NullTime{
Time: database.Now(),
Valid: true,
},
})
require.NoError(t, err)
}
for _, tc := range []struct {