This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new bc8f0c4 ci(catalog): Enable Glue RenameTable test (#383)
bc8f0c4 is described below
commit bc8f0c41c62e73b70309dc11dc673e3739e664ac
Author: Mani Chandrasekar <[email protected]>
AuthorDate: Tue Apr 15 13:15:41 2025 -0700
ci(catalog): Enable Glue RenameTable test (#383)
- Added support to stub S3 FileSystem read / write
- Added [AWS Middleware
Stubber](https://pkg.go.dev/github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools)
dependency to hooks into the AWS SDK
- Enable GlueCatalog RenameTable test
---------
Co-authored-by: Matt Topol <[email protected]>
---
catalog/glue/glue_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++--
go.mod | 1 +
go.sum | 2 ++
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/catalog/glue/glue_test.go b/catalog/glue/glue_test.go
index ddedf4a..3e9cafd 100644
--- a/catalog/glue/glue_test.go
+++ b/catalog/glue/glue_test.go
@@ -19,8 +19,10 @@ package glue
import (
"context"
+ "encoding/json"
"errors"
"fmt"
+ "io"
"os"
"strings"
"testing"
@@ -34,6 +36,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/glue"
"github.com/aws/aws-sdk-go-v2/service/glue/types"
"github.com/aws/aws-sdk-go-v2/service/s3"
+ "github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@@ -143,6 +146,24 @@ var testNonIcebergGlueTable = types.Table{
},
}
+var testSchema = iceberg.NewSchemaWithIdentifiers(0, []int{2},
+ iceberg.NestedField{ID: 1, Name: "foo", Type:
iceberg.PrimitiveTypes.String},
+ iceberg.NestedField{ID: 2, Name: "bar", Type:
iceberg.PrimitiveTypes.Int32, Required: true},
+ iceberg.NestedField{ID: 3, Name: "baz", Type:
iceberg.PrimitiveTypes.Bool})
+
+var testPartitionSpec = iceberg.NewPartitionSpec(
+ iceberg.PartitionField{SourceID: 2, FieldID: 1000, Transform:
iceberg.IdentityTransform{}, Name: "bar"})
+
+var testSortOrder = table.SortOrder{
+ OrderID: 1,
+ Fields: []table.SortField{
+ {
+ SourceID: 1, Transform: iceberg.IdentityTransform{},
+ Direction: table.SortASC, NullOrder: table.NullsLast,
+ },
+ },
+}
+
func TestGlueGetTable(t *testing.T) {
assert := require.New(t)
@@ -603,8 +624,6 @@ func TestGlueUpdateNamespaceProperties(t *testing.T) {
}
func TestGlueRenameTable(t *testing.T) {
- t.Skip("Skipping this test temporarily because LoadTable is not
testable due to the dependency on the IO.")
-
assert := require.New(t)
mockGlueSvc := &mockGlueClient{}
@@ -659,13 +678,35 @@ func TestGlueRenameTable(t *testing.T) {
Name: aws.String("test_table"),
}, mock.Anything).Return(&glue.DeleteTableOutput{}, nil).Once()
+ // Setup S3 FS stubs to mimic reading json metadata file
+ stubber := testtools.NewStubber()
+ testMetadata, err := table.NewMetadata(
+ testSchema, &testPartitionSpec, testSortOrder,
"s3://test-bucket/new_test_table/", nil)
+ assert.NoError(err)
+ strMeta, err := json.Marshal(testMetadata)
+ assert.NoError(err)
+
+ stubber.Add(testtools.Stub{
+ OperationName: "GetObject",
+ Input: &s3.GetObjectInput{
+ Bucket: aws.String("test-bucket"),
+ Key:
aws.String("new_test_table/metadata/abc123-123.metadata.json"),
+ ChecksumMode: "ENABLED",
+ },
+ Output: &s3.GetObjectOutput{
+ Body: io.NopCloser(strings.NewReader(string(strMeta))),
+ },
+ })
+
glueCatalog := &Catalog{
glueSvc: mockGlueSvc,
+ awsCfg: stubber.SdkConfig,
}
renamedTable, err := glueCatalog.RenameTable(context.TODO(),
TableIdentifier("test_database", "test_table"),
TableIdentifier("test_database", "new_test_table"))
assert.NoError(err)
assert.Equal("new_test_table", renamedTable.Identifier()[1])
+ assert.True(testSchema.Equals(renamedTable.Schema()))
}
func TestGlueRenameTable_DeleteTableFailureRollback(t *testing.T) {
diff --git a/go.mod b/go.mod
index 0e5eabd..80494fa 100644
--- a/go.mod
+++ b/go.mod
@@ -30,6 +30,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/glue v1.109.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.2
github.com/aws/smithy-go v1.22.3
+ github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools
v0.0.0-20250407191926-092f3e54b837
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/google/uuid v1.6.0
github.com/hamba/avro/v2 v2.28.0
diff --git a/go.sum b/go.sum
index 1406f8f..8a27a5c 100644
--- a/go.sum
+++ b/go.sum
@@ -154,6 +154,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.33.19
h1:1XuUZ8mYJw9B6lzAkXhqHlJd/Xv
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19/go.mod
h1:cQnB8CUnxbMU82JvlqjKR2HBOm3fe9pWorWBza6MBJ4=
github.com/aws/smithy-go v1.22.3
h1:Z//5NuZCSW6R4PhQ93hShNbyBbn8BWCmCVCt+Q8Io5k=
github.com/aws/smithy-go v1.22.3/go.mod
h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
+github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools
v0.0.0-20250407191926-092f3e54b837
h1:8eMceEa0ib+nqJuGsyowuZaVBVAr685oK6WrNIit+0g=
+github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools
v0.0.0-20250407191926-092f3e54b837/go.mod
h1:9Oj/8PZn3D5Ftp/Z1QWrIEFE0daERMqfJawL9duHRfc=
github.com/beorn7/perks v0.0.0-20150223135152-b965b613227f/go.mod
h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod
h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod
h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=