Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ Deployment complete!
"status": {
"branch_logical_size_limit_bytes": [NUMID],
"default_branch": "projects/test-pg-proj-hard-[UNIQUE_NAME]/branches/production",
"default_endpoint_settings": {
"autoscaling_limit_max_cu": 1,
"autoscaling_limit_min_cu": 1,
"suspend_timeout_duration": "86400s"
},
"display_name": "purge_on_delete = true",
"enable_pg_native_login": false,
"history_retention_duration": "604800s",
"owner": "[USERNAME]",
"pg_version": 16,
"project_id": "test-pg-proj-hard-[UNIQUE_NAME]",
Expand All @@ -36,8 +42,14 @@ Deployment complete!
"status": {
"branch_logical_size_limit_bytes": [NUMID],
"default_branch": "projects/test-pg-proj-soft-[UNIQUE_NAME]/branches/production",
"default_endpoint_settings": {
"autoscaling_limit_max_cu": 1,
"autoscaling_limit_min_cu": 1,
"suspend_timeout_duration": "86400s"
},
"display_name": "purge_on_delete unset (soft delete)",
"enable_pg_native_login": false,
"history_retention_duration": "604800s",
"owner": "[USERNAME]",
"pg_version": 16,
"project_id": "test-pg-proj-soft-[UNIQUE_NAME]",
Expand Down
36 changes: 31 additions & 5 deletions libs/testserver/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ func nowTime() *sdktime.Time {
return sdktime.New(time.Now().UTC())
}

// Backend defaults applied to a project's status when the spec omits them.
// These mirror the values the real API materializes on create.
const (
defaultHistoryRetention = 604800 * time.Second // 7 days
defaultSuspendTimeout = 86400 * time.Second // 1 day
defaultAutoscalingLimitMinCu = 1
defaultAutoscalingLimitMaxCu = 1
)

// postgresErrorResponse creates an error response with error code for postgres API.
func postgresErrorResponse(statusCode int, errorCode, message string) Response {
return Response{
Expand Down Expand Up @@ -103,23 +112,40 @@ func (s *FakeWorkspace) PostgresProjectCreate(req Request, projectID string) Res

// Copy spec fields to status (API returns status as materialized view)
if project.Spec != nil {
// The backend materializes a default retention when the spec omits it.
historyRetention := project.Spec.HistoryRetentionDuration
if historyRetention == nil {
historyRetention = duration.New(defaultHistoryRetention)
}

project.Status = &postgres.ProjectStatus{
ProjectId: projectID,
DefaultBranch: name + "/branches/production",
DisplayName: project.Spec.DisplayName,
PgVersion: project.Spec.PgVersion,
HistoryRetentionDuration: project.Spec.HistoryRetentionDuration,
HistoryRetentionDuration: historyRetention,
EnablePgNativeLogin: false,
Owner: TestUser.UserName,
BranchLogicalSizeLimitBytes: 8796093022208, // 8 TB (real API default)
SyntheticStorageSizeBytes: 0,
ForceSendFields: []string{"EnablePgNativeLogin", "SyntheticStorageSizeBytes"},
}

// The backend materializes default endpoint settings when the spec omits them.
project.Status.DefaultEndpointSettings = &postgres.ProjectDefaultEndpointSettings{
AutoscalingLimitMinCu: defaultAutoscalingLimitMinCu,
AutoscalingLimitMaxCu: defaultAutoscalingLimitMaxCu,
SuspendTimeoutDuration: duration.New(defaultSuspendTimeout),
}
if project.Spec.DefaultEndpointSettings != nil {
project.Status.DefaultEndpointSettings = &postgres.ProjectDefaultEndpointSettings{
AutoscalingLimitMinCu: project.Spec.DefaultEndpointSettings.AutoscalingLimitMinCu,
AutoscalingLimitMaxCu: project.Spec.DefaultEndpointSettings.AutoscalingLimitMaxCu,
SuspendTimeoutDuration: project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration,
if project.Spec.DefaultEndpointSettings.AutoscalingLimitMinCu != 0 {
project.Status.DefaultEndpointSettings.AutoscalingLimitMinCu = project.Spec.DefaultEndpointSettings.AutoscalingLimitMinCu
}
if project.Spec.DefaultEndpointSettings.AutoscalingLimitMaxCu != 0 {
project.Status.DefaultEndpointSettings.AutoscalingLimitMaxCu = project.Spec.DefaultEndpointSettings.AutoscalingLimitMaxCu
}
if project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration != nil {
project.Status.DefaultEndpointSettings.SuspendTimeoutDuration = project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration
}
}
// Clear spec so it's not returned in response (API only returns status)
Expand Down
Loading