Skip to content

Commit

Permalink
update Mockgcp for sqlinstance, sqluser, and sqldatabse
Browse files Browse the repository at this point in the history
  • Loading branch information
600lyy committed Nov 6, 2024
1 parent 56d7b21 commit 28f9901
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mockgcp/mocksql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ func (s *MockService) NewHTTPMux(ctx context.Context, conn *grpc.ClientConn) (ht
error.Message = "The Cloud SQL instance does not exist."
error.Status = ""
}

for errIdx := range error.Errors {
if strings.HasPrefix(error.Errors[errIdx].Message, "database ") {
error.Errors[errIdx].Message = "Not Found."
error.Errors[errIdx].Reason = "notFound"
}
}
if strings.HasPrefix(error.Message, "database ") {
error.Message = "Not Found"
error.Status = ""
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion mockgcp/mocksql/sqlinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func setDatabaseVersionDefaults(obj *pb.DatabaseInstance) error {
switch obj.DatabaseVersion {
case pb.SqlDatabaseVersion_MYSQL_5_7:
obj.DatabaseInstalledVersion = "MYSQL_5_7_44"
obj.MaintenanceVersion = "MYSQL_5_7_44.R20231105.01_03"
obj.MaintenanceVersion = "MYSQL_5_7_44.R20241020.00_00"
obj.UpgradableDatabaseVersions = []*pb.AvailableDatabaseVersion{
{
DisplayName: asRef("MySQL 8.0"),
Expand Down Expand Up @@ -359,6 +359,11 @@ func setDatabaseVersionDefaults(obj *pb.DatabaseInstance) error {
MajorVersion: asRef("MYSQL_8_0"),
Name: asRef("MYSQL_8_0_37"),
},
{
DisplayName: asRef("MySQL 8.0.39"),
MajorVersion: asRef("MYSQL_8_0"),
Name: asRef("MYSQL_8_0_39"),
},
}
case pb.SqlDatabaseVersion_MYSQL_8_0:
obj.DatabaseInstalledVersion = "MYSQL_8_0_31"
Expand Down Expand Up @@ -521,6 +526,7 @@ func populateDefaults(obj *pb.DatabaseInstance) {
Entitled: asRef(false),
FlagRecommenderEnabled: asRef(false),
IndexAdvisorEnabled: asRef(false),
ActiveQueryEnabled: asRef(false),
}
} else if isPostgres(obj) {
obj.GeminiConfig = &pb.GeminiInstanceConfig{
Expand Down
5 changes: 5 additions & 0 deletions mockgcp/mocksql/sqluser.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func (s *sqlUsersService) Insert(ctx context.Context, req *pb.SqlUsersInsertRequ
obj.Project = name.Project.ID
obj.Instance = name.Instance
obj.Kind = "sql#user"
if obj.GetPasswordPolicy() == nil {
obj.PasswordPolicy = &pb.UserPasswordValidationPolicy{
Status: &pb.PasswordStatus{},
}
}

obj.Etag = fields.ComputeWeakEtag(obj)

Expand Down

0 comments on commit 28f9901

Please sign in to comment.