@@ -112,8 +112,7 @@ func TestHealthcareToolEndpoints(t *testing.T) {
112112 fhirStoreID := "fhir-store-" + uuid .New ().String ()
113113 dicomStoreID := "dicom-store-" + uuid .New ().String ()
114114
115- patient1ID , patient2ID , teardown := setupHealthcareResources (t , healthcareService , healthcareDataset , fhirStoreID , dicomStoreID )
116- defer teardown (t )
115+ patient1ID , patient2ID := setupHealthcareResources (t , healthcareService , healthcareDataset , fhirStoreID , dicomStoreID )
117116
118117 toolsFile := getToolsConfig (sourceConfig )
119118 toolsFile = addClientAuthSourceConfig (t , toolsFile )
@@ -173,10 +172,8 @@ func TestHealthcareToolWithStoreRestriction(t *testing.T) {
173172 disallowedFHIRStoreID := "fhir-store-disallowed-" + uuid .New ().String ()
174173 disallowedDICOMStoreID := "dicom-store-disallowed-" + uuid .New ().String ()
175174
176- _ , _ , teardownAllowedStores := setupHealthcareResources (t , healthcareService , healthcareDataset , allowedFHIRStoreID , allowedDICOMStoreID )
177- defer teardownAllowedStores (t )
178- _ , _ , teardownDisallowedStores := setupHealthcareResources (t , healthcareService , healthcareDataset , disallowedFHIRStoreID , disallowedDICOMStoreID )
179- defer teardownDisallowedStores (t )
175+ setupHealthcareResources (t , healthcareService , healthcareDataset , allowedFHIRStoreID , allowedDICOMStoreID )
176+ setupHealthcareResources (t , healthcareService , healthcareDataset , disallowedFHIRStoreID , disallowedDICOMStoreID )
180177
181178 // Configure source with dataset restriction.
182179 sourceConfig ["allowedFhirStores" ] = []string {allowedFHIRStoreID }
@@ -257,7 +254,7 @@ func newHealthcareService(ctx context.Context) (*healthcare.Service, error) {
257254 return healthcareService , nil
258255}
259256
260- func setupHealthcareResources (t * testing.T , service * healthcare.Service , datasetID , fhirStoreID , dicomStoreID string ) (string , string , func ( * testing. T ) ) {
257+ func setupHealthcareResources (t * testing.T , service * healthcare.Service , datasetID , fhirStoreID , dicomStoreID string ) (string , string ) {
261258 datasetName := fmt .Sprintf ("projects/%s/locations/%s/datasets/%s" , healthcareProject , healthcareRegion , datasetID )
262259 var err error
263260
@@ -266,12 +263,24 @@ func setupHealthcareResources(t *testing.T, service *healthcare.Service, dataset
266263 if fhirStore , err = service .Projects .Locations .Datasets .FhirStores .Create (datasetName , fhirStore ).FhirStoreId (fhirStoreID ).Do (); err != nil {
267264 t .Fatalf ("failed to create fhir store: %v" , err )
268265 }
266+ // Register cleanup
267+ t .Cleanup (func () {
268+ if _ , err := service .Projects .Locations .Datasets .FhirStores .Delete (fhirStore .Name ).Do (); err != nil {
269+ t .Logf ("failed to delete fhir store: %v" , err )
270+ }
271+ })
269272
270273 // Create DICOM store
271274 dicomStore := & healthcare.DicomStore {}
272275 if dicomStore , err = service .Projects .Locations .Datasets .DicomStores .Create (datasetName , dicomStore ).DicomStoreId (dicomStoreID ).Do (); err != nil {
273276 t .Fatalf ("failed to create dicom store: %v" , err )
274277 }
278+ // Register cleanup
279+ t .Cleanup (func () {
280+ if _ , err := service .Projects .Locations .Datasets .DicomStores .Delete (dicomStore .Name ).Do (); err != nil {
281+ t .Logf ("failed to delete dicom store: %v" , err )
282+ }
283+ })
275284
276285 // Create Patient 1
277286 patient1Body := bytes .NewBuffer ([]byte (`{
@@ -317,15 +326,7 @@ func setupHealthcareResources(t *testing.T, service *healthcare.Service, dataset
317326 createFHIRResource (t , service , fhirStore .Name , "Observation" , observation2Body )
318327 }
319328
320- teardown := func (t * testing.T ) {
321- if _ , err := service .Projects .Locations .Datasets .FhirStores .Delete (fhirStore .Name ).Do (); err != nil {
322- t .Logf ("failed to delete fhir store: %v" , err )
323- }
324- if _ , err := service .Projects .Locations .Datasets .DicomStores .Delete (dicomStore .Name ).Do (); err != nil {
325- t .Logf ("failed to delete dicom store: %v" , err )
326- }
327- }
328- return patient1ID , patient2ID , teardown
329+ return patient1ID , patient2ID
329330}
330331
331332func getToolsConfig (sourceConfig map [string ]any ) map [string ]any {
0 commit comments