Revanth14 commented on code in PR #1285:
URL: https://github.com/apache/iceberg-go/pull/1285#discussion_r3470677618


##########
catalog/glue/glue_test.go:
##########
@@ -451,6 +459,116 @@ func TestGlueDropTable(t *testing.T) {
        assert.NoError(err)
 }
 
+func TestGluePurgeTable(t *testing.T) {
+       assert := require.New(t)
+       ctx := context.Background()
+       tableLocation := filepath.Join(t.TempDir(), "warehouse", 
"test_database", "test_table")
+       metadataLocation, dataFile := writeGluePurgeTableFiles(t, tableLocation)
+       glueTable := gluePurgeTable(metadataLocation)
+
+       mockGlueSvc := &mockGlueClient{}
+       mockGlueSvc.On("GetTable", mock.Anything, &glue.GetTableInput{
+               DatabaseName: aws.String("test_database"),
+               Name:         aws.String("test_table"),
+       }, mock.Anything).Return(&glue.GetTableOutput{Table: &glueTable}, 
nil).Twice()
+       mockGlueSvc.On("DeleteTable", mock.Anything, &glue.DeleteTableInput{
+               DatabaseName: aws.String("test_database"),
+               Name:         aws.String("test_table"),
+       }, mock.Anything).Return(&glue.DeleteTableOutput{}, nil).Once()
+
+       glueCatalog := &Catalog{glueSvc: mockGlueSvc}
+
+       assert.NoError(glueCatalog.PurgeTable(ctx, 
TableIdentifier("test_database", "test_table")))
+       assert.NoFileExists(metadataLocation)
+       assert.NoFileExists(dataFile)
+       mockGlueSvc.AssertExpectations(t)
+}
+
+func TestGluePurgeTableSwallowsPurgeFilesError(t *testing.T) {
+       assert := require.New(t)
+       ctx := context.Background()
+       const scheme = "gluepurgefail"
+       failingFS := failRemoveIO{MemFS: iceio.NewMemFS(), err: 
errGluePurgeRemove}
+       iceio.Register(scheme, func(context.Context, *url.URL, 
map[string]string) (iceio.IO, error) {
+               return failingFS, nil
+       })
+       t.Cleanup(func() { iceio.Unregister(scheme) })
+
+       tableLocation := scheme + "://bucket/test_database/test_table"
+       metadataLocation := tableLocation + "/metadata/v1.metadata.json"
+       dataFile := tableLocation + "/data/file.parquet"
+       writeGluePurgeTableMetadata(t, failingFS, tableLocation, 
metadataLocation)
+       require.NoError(t, failingFS.WriteFile(dataFile, []byte("data")))
+       glueTable := gluePurgeTable(metadataLocation)
+
+       mockGlueSvc := &mockGlueClient{}
+       mockGlueSvc.On("GetTable", mock.Anything, &glue.GetTableInput{
+               DatabaseName: aws.String("test_database"),
+               Name:         aws.String("test_table"),
+       }, mock.Anything).Return(&glue.GetTableOutput{Table: &glueTable}, 
nil).Twice()
+       mockGlueSvc.On("DeleteTable", mock.Anything, &glue.DeleteTableInput{
+               DatabaseName: aws.String("test_database"),
+               Name:         aws.String("test_table"),
+       }, mock.Anything).Return(&glue.DeleteTableOutput{}, nil).Once()
+
+       var logs bytes.Buffer
+       originalLogOutput := log.Writer()
+       log.SetOutput(&logs)
+       t.Cleanup(func() { log.SetOutput(originalLogOutput) })
+
+       glueCatalog := &Catalog{glueSvc: mockGlueSvc}
+
+       assert.NoError(glueCatalog.PurgeTable(ctx, 
TableIdentifier("test_database", "test_table")))
+       assert.Contains(logs.String(), "failed to purge files")
+       assert.Contains(logs.String(), errGluePurgeRemove.Error())
+       file, err := failingFS.Open(dataFile)

Review Comment:
   Addressed in both Glue and Hive. Added an explicit `assert.NotNil(file)` 
after `Open` before calling `Close`, so the nil safety is no longer implicit in 
the `require.New(t)` alias.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to