Skip to content

Commit b8586f5

Browse files
denikclaude
andauthored
testserver: match cloud API behavior for database_catalogs (#4440)
## Changes - Assign uid in CREATE response - Do not return create_database_if_not_exists in GET (write-only field) ## Why This causes the migrate test to exercise the code path where database_catalogs has an Update action (due to the field difference), which triggered a nil pointer panic before commit a0418ac. ## Tests Revert #4438 - can now see panic with local testserver. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a0418ac commit b8586f5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

libs/testserver/database_catalogs.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,34 @@ func (s *FakeWorkspace) DatabaseCatalogCreate(req Request) Response {
3434
}
3535
}
3636

37+
// Assign uid like the real backend does
38+
databaseCatalog.Uid = nextUUID()
39+
3740
s.DatabaseCatalogs[databaseCatalog.Name] = databaseCatalog
3841

3942
return Response{
4043
Body: databaseCatalog,
4144
}
4245
}
4346

47+
func (s *FakeWorkspace) DatabaseCatalogGet(name string) Response {
48+
defer s.LockUnlock()()
49+
50+
catalog, ok := s.DatabaseCatalogs[name]
51+
if !ok {
52+
return Response{
53+
Body: fmt.Sprintf("database catalog with name '%s' not found", name),
54+
StatusCode: 404,
55+
}
56+
}
57+
58+
// create_database_if_not_exists is a write-only field - the real API doesn't return it
59+
result := catalog
60+
result.CreateDatabaseIfNotExists = false
61+
62+
return Response{Body: result}
63+
}
64+
4465
func (s *FakeWorkspace) DatabaseCatalogUpdate(req Request, name string) Response {
4566
defer s.LockUnlock()()
4667

libs/testserver/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func AddDefaultHandlers(server *Server) {
607607
})
608608

609609
server.Handle("GET", "/api/2.0/database/catalogs/{name}", func(req Request) any {
610-
return MapGet(req.Workspace, req.Workspace.DatabaseCatalogs, req.Vars["name"])
610+
return req.Workspace.DatabaseCatalogGet(req.Vars["name"])
611611
})
612612

613613
server.Handle("PATCH", "/api/2.0/database/catalogs/{name}", func(req Request) any {

0 commit comments

Comments
 (0)