Revanth14 commented on code in PR #1285:
URL: https://github.com/apache/iceberg-go/pull/1285#discussion_r3470655090
##########
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)
Review Comment:
Good point. I dropped the log inspection entirely so the tests no longer
mutate the process-global logger. The swallow tests now focus on the actual
contract: `PurgeTable` returns nil, the catalog entry is dropped before any
file removal attempt, and the data file remains when removal fails.
--
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]