Skip to content

Commit

Permalink
add more tests and rename the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Feb 28, 2025
1 parent 3754464 commit 72550fa
Show file tree
Hide file tree
Showing 166 changed files with 4,037 additions and 49 deletions.
28 changes: 27 additions & 1 deletion connector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,33 @@ func TestConnector(t *testing.T) {

ndctest.TestConnector(t, &Connector{}, ndctest.TestConnectorOptions{
Configuration: "../tests/configuration",
TestDataDir: filepath.Join("testdata", dir),
TestDataDir: filepath.Join("testdata", "static", dir),
ServerOptions: serverOptions,
})
}
}

func TestConnectorDynamicCredentials(t *testing.T) {
configDir := os.Getenv("CONFIG_DIR")
if configDir != "../tests/configuration" {
return
}

setConnectorTestEnv(t)

for i, dir := range []string{"01-setup", "02-get", "03-cleanup"} {
var serverOptions []connector.ServeOption

if i == 0 {
logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
serverOptions = append(serverOptions, connector.WithLogger(logger))
}

ndctest.TestConnector(t, &Connector{}, ndctest.TestConnectorOptions{
Configuration: "../tests/configuration",
TestDataDir: filepath.Join("testdata", "dynamic", dir),
ServerOptions: serverOptions,
})
}
Expand Down
12 changes: 6 additions & 6 deletions connector/functions/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func FunctionStorageObject(ctx context.Context, state *types.State, args *common
return state.Storage.StatObject(ctx, request.GetBucketArguments(), request.ObjectNamePredicate.GetPrefix(), opts)
}

// FunctionDownloadStorageObjectAsBytes returns a stream of the object data. Most of the common errors occur when reading the stream.
func FunctionDownloadStorageObjectAsBytes(ctx context.Context, state *types.State, args *common.GetStorageObjectArguments) (DownloadStorageObjectResponse, error) {
// FunctionDownloadStorageObjectAsBase64 returns a stream of the object data. Most of the common errors occur when reading the stream.
func FunctionDownloadStorageObjectAsBase64(ctx context.Context, state *types.State, args *common.GetStorageObjectArguments) (DownloadStorageObjectResponse, error) {
args.Base64Encoded = true

reader, err := downloadStorageObject(ctx, state, args)
Expand Down Expand Up @@ -203,9 +203,9 @@ func FunctionStorageIncompleteUploads(ctx context.Context, state *types.State, a
return state.Storage.ListIncompleteUploads(ctx, args.StorageBucketArguments, args.ListIncompleteUploadsOptions)
}

// ProcedureUploadStorageObject uploads object that are less than 128MiB in a single PUT operation. For objects that are greater than 128MiB in size,
// ProcedureUploadStorageObjectAsBase64 uploads object that are less than 128MiB in a single PUT operation. For objects that are greater than 128MiB in size,
// PutObject seamlessly uploads the object as parts of 128MiB or more depending on the actual file size. The max upload size for an object is 5TB.
func ProcedureUploadStorageObject(ctx context.Context, state *types.State, args *PutStorageObjectBase64Arguments) (common.StorageUploadInfo, error) {
func ProcedureUploadStorageObjectAsBase64(ctx context.Context, state *types.State, args *PutStorageObjectBase64Arguments) (common.StorageUploadInfo, error) {
return uploadStorageObject(ctx, state, &args.PutStorageObjectArguments, args.Data.Bytes())
}

Expand All @@ -230,8 +230,8 @@ func uploadStorageObject(ctx context.Context, state *types.State, args *PutStora
return *result, nil
}

// ProcedureUploadStorageObjectText uploads object in plain text to the storage server. The file content is not encoded to base64 so the input size is smaller than 30%.
func ProcedureUploadStorageObjectText(ctx context.Context, state *types.State, args *PutStorageObjectTextArguments) (common.StorageUploadInfo, error) {
// ProcedureUploadStorageObjectAsText uploads object in plain text to the storage server. The file content is not encoded to base64 so the input size is smaller than 30%.
func ProcedureUploadStorageObjectAsText(ctx context.Context, state *types.State, args *PutStorageObjectTextArguments) (common.StorageUploadInfo, error) {
return uploadStorageObject(ctx, state, &args.PutStorageObjectArguments, []byte(args.Data))
}

Expand Down
16 changes: 8 additions & 8 deletions connector/functions/types.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions connector/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestConnectorQueries(t *testing.T) {
Operations: []schema.MutationOperation{
{
Type: schema.MutationOperationProcedure,
Name: "uploadStorageObjectText",
Name: "uploadStorageObjectAsText",
Arguments: rawArguments,
Fields: schema.NewNestedObject(map[string]schema.FieldEncoder{
"name": schema.NewColumnField("name", nil),
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestMaxDownloadSizeValidation(t *testing.T) {
MaxDownloadSizeMBs float64
}{
{
Name: "downloadStorageObjectAsBytes",
Name: "downloadStorageObjectAsBase64",
MaxDownloadSizeMBs: 1.33,
},
{
Expand All @@ -215,5 +215,4 @@ func TestMaxDownloadSizeValidation(t *testing.T) {
resp.Body.Close()
})
}

}
6 changes: 3 additions & 3 deletions connector/schema.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"collection_relationships": {},
"operations": [
{
"type": "procedure",
"name": "createStorageBucket",
"arguments": {
"clientType": "azblob",
"endpoint": "http://local.hasura.dev:10000",
"accessKeyId": "local",
"secretAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"name": "azblob-dynamic",
"objectLock": false,
"region": "us-east-1",
"tags": [
{
"key": "UserID",
"value": "1"
}
]
},
"fields": {
"fields": {
"success": {
"column": "success",
"type": "column"
}
},
"type": "object"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"collection_relationships": {},
"operations": [
{
"type": "procedure",
"name": "updateStorageBucket",
"arguments": {
"clientType": "azblob",
"endpoint": "http://local.hasura.dev:10000",
"accessKeyId": "local",
"secretAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"bucket": "azblob-dynamic",
"tags": [
{
"key": "Foo",
"value": "baz"
}
]
},
"fields": {
"fields": {
"success": {
"column": "success",
"type": "column"
}
},
"type": "object"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"operation_results": [
{
"result": {
"bucket": "azblob-dynamic",
"checksumCrc32": null,
"checksumCrc32C": null,
"checksumCrc64Nvme": null,
"checksumSha1": null,
"checksumSha256": null,
"contentMd5": "KZ0tkTzqqDd9IiRNs5cjyg==",
"expiration": null,
"expirationRuleId": null,
"location": null,
"name": "public/hello.txt",
"size": null
},
"type": "procedure"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"collection_relationships": {},
"operations": [
{
"type": "procedure",
"name": "uploadStorageObjectAsBase64",
"arguments": {
"clientType": "azblob",
"endpoint": "http://local.hasura.dev:10000",
"accessKeyId": "local",
"secretAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"bucket": "azblob-dynamic",
"data": "SVpHWjhMMHZzVw==",
"object": "public/hello.txt",
"options": {
"autoChecksum": "SHA256",
"cacheControl": "max-age=180, public",
"checksum": "SHA256",
"clientId": "s3",
"concurrentStreamParts": false,
"contentDisposition": "attachment",
"contentEncoding": "gzip",
"contentLanguage": "en-US",
"contentType": "text/plain",
"disableContentSha256": false,
"disableMultipart": false,
"expires": "2099-01-01T00:00:00Z",
"numThreads": 1,
"partSize": 1024000000,
"sendContentMd5": true,
"storageClass": "Cool",
"metadata": [
{
"key": "Foo",
"value": "Bar"
}
],
"tags": [
{
"key": "UserID",
"value": "1"
}
],
"websiteRedirectLocation": "http://localhost:9001"
}
},
"fields": {
"fields": {
"bucket": {
"column": "bucket",
"type": "column"
},
"checksumCrc32": {
"column": "checksumCrc32",
"type": "column"
},
"checksumCrc32C": {
"column": "checksumCrc32C",
"type": "column"
},
"checksumCrc64Nvme": {
"column": "checksumCrc64Nvme",
"type": "column"
},
"checksumSha1": {
"column": "checksumSha1",
"type": "column"
},
"checksumSha256": {
"column": "checksumSha256",
"type": "column"
},
"contentMd5": {
"column": "contentMd5",
"type": "column"
},
"expiration": {
"column": "expiration",
"type": "column"
},
"expirationRuleId": {
"column": "expirationRuleId",
"type": "column"
},
"location": {
"column": "location",
"type": "column"
},
"name": {
"column": "name",
"type": "column"
},
"size": {
"column": "size",
"type": "column"
}
},
"type": "object"
}
}
]
}
Loading

0 comments on commit 72550fa

Please sign in to comment.