-
Notifications
You must be signed in to change notification settings - Fork 37
feat(go): add TransformationOptions for ingestion transporter configuration #6293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MarioAlexandruDan
wants to merge
35
commits into
main
Choose a base branch
from
feat/go-transformation-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e121399
feat(client): add TransformationOptions support for ingestion transpo…
MarioAlexandruDan 5860244
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 154ce9c
fix(go): wire generated files and move manual tests to correct package
MarioAlexandruDan 776cd12
feat(go): implement TransformationOptions for ingestion transporter c…
MarioAlexandruDan 36615ff
feat(client): add TransformationOptions support for API client config…
MarioAlexandruDan 13bffb2
fix(go): wire generated files and move manual tests to correct package
MarioAlexandruDan a00567b
fix(go): remove accidentally committed test file from wrong package
MarioAlexandruDan 5579d3f
fix(go): generate transformation_options.go from template instead of …
MarioAlexandruDan d31b2d2
fix(go): update generation config to include Go module and exclude ma…
MarioAlexandruDan 304835d
fix(go): exclude manual test files from generation config
MarioAlexandruDan 1b55c73
fix(go): avoid inline error handling in SetTransformationOptions to s…
MarioAlexandruDan eebc0bd
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 9f4f75b
feat(go): introduce ClientOptions struct for configurable ingestion t…
MarioAlexandruDan ba537dc
feat(go): update transformation options to use ClientOptions for conf…
MarioAlexandruDan f6c1dba
fix(go): correct syntax for transformation options in createClient.mu…
MarioAlexandruDan 79b02de
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 750dca2
refactor(go): remove deprecated SetTransformationRegion method and re…
MarioAlexandruDan f8d55f4
Merge remote-tracking branch 'origin/feat/go-transformation-options' …
MarioAlexandruDan 21d8119
fix(go): correct DefaultHeaders to DefaultHeader in transformation op…
MarioAlexandruDan fdf3e43
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 9c6d4a4
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan cc68c68
refactor(go): remove unused import and enhance error handling in tran…
MarioAlexandruDan 91ddcb4
fix(go): ensure error handling for SetTransformationOptions in create…
MarioAlexandruDan 7d5d310
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan fba4997
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 1d19eb7
refactor(go): simplify TransformationOptions structure and update rel…
MarioAlexandruDan 0982e57
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 3f17e4a
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 3837ccf
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 5674b86
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan d6a3794
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan c96159e
feat(go): add TransformationOptions to ingestion client configuration
MarioAlexandruDan bb437ac
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan 235f9ee
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan ca9fa85
Merge branch 'main' into feat/go-transformation-options
MarioAlexandruDan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // {{{generationBanner}}} | ||
| package {{packageName}} | ||
|
|
||
| import ( | ||
| "errors" | ||
| "time" | ||
|
|
||
| "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" | ||
| "github.com/algolia/algoliasearch-client-go/v4/algolia/ingestion" | ||
| "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" | ||
| ) | ||
|
|
||
| // TransformationOptions configures the ingestion transporter used by *WithTransformation helpers. | ||
| // When passed to NewClient or set via SetTransformationOptions, the transporter is eagerly created | ||
| // using Ingestion API defaults (25s timeouts, no compression). Only fields explicitly set here override | ||
| // those defaults. The parent search config is NOT forwarded to the ingestion transporter. | ||
| // See https://www.algolia.com/doc/libraries/sdk/methods/ingestion | ||
| type TransformationOptions struct { | ||
| Region ingestion.Region // required | ||
| ReadTimeout time.Duration | ||
| WriteTimeout time.Duration | ||
| ConnectTimeout time.Duration | ||
| Compression compression.Compression | ||
| Hosts []transport.StatefulHost | ||
| DefaultHeader map[string]string | ||
| } | ||
|
|
||
| func (o TransformationOptions) validate() error { | ||
| if o.Region == "" { | ||
| return errors.New("Region is required in TransformationOptions. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ClientOption configures the search client at construction time. | ||
| type ClientOption func(*SearchConfiguration) | ||
|
|
||
| // WithTransformationOptions returns a ClientOption that configures the ingestion transporter. | ||
| func WithTransformationOptions(opts TransformationOptions) ClientOption { | ||
| return func(cfg *SearchConfiguration) { | ||
| cfg.TransformationOptions = &opts | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
tests/output/go/tests/manual/transformation_options_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package manual | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/algolia/algoliasearch-client-go/v4/algolia/search" | ||
| ) | ||
|
|
||
| func TestTransformationOptionsRegionRequired(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey") | ||
| require.NoError(t, err) | ||
| err = client.SetTransformationOptions(search.TransformationOptions{}) | ||
| require.ErrorContains(t, err, "Region is required in TransformationOptions") | ||
| } | ||
|
|
||
| func TestTransformationOptionsRegionRequiredAtConstruction(t *testing.T) { | ||
| _, err := search.NewClient("appID", "apiKey", | ||
| search.WithTransformationOptions(search.TransformationOptions{}), | ||
| ) | ||
| require.ErrorContains(t, err, "Region is required in TransformationOptions") | ||
| } | ||
|
|
||
| func TestTransformationOptionsRegionOnlyHasZeroOverrides(t *testing.T) { | ||
| opts := search.TransformationOptions{Region: "us"} | ||
| require.Equal(t, "us", string(opts.Region)) | ||
| require.Zero(t, opts.ReadTimeout) | ||
| } | ||
|
|
||
| func TestTransformationOptionsWithOverrides(t *testing.T) { | ||
| opts := search.TransformationOptions{Region: "eu", ReadTimeout: 50 * time.Second} | ||
| require.Equal(t, "eu", string(opts.Region)) | ||
| require.Equal(t, 50*time.Second, opts.ReadTimeout) | ||
| } | ||
|
|
||
| func TestTransformationOptionsWithRegionOnly(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey") | ||
| require.NoError(t, err) | ||
| err = client.SetTransformationOptions(search.TransformationOptions{Region: "us"}) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestIngestionTransporterNilBeforeSet(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey") | ||
| require.NoError(t, err) | ||
| _, err = client.SaveObjectsWithTransformation("index", []map[string]any{{"objectID": "1"}}) | ||
| require.ErrorContains(t, err, "TransformationOptions must be set") | ||
| } | ||
|
|
||
| func TestSetTransformationOptionsCreatesTransporter(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey") | ||
| require.NoError(t, err) | ||
| _, err = client.SaveObjectsWithTransformation("index", []map[string]any{{"objectID": "1"}}) | ||
| require.ErrorContains(t, err, "TransformationOptions must be set") | ||
| require.NoError(t, client.SetTransformationOptions(search.TransformationOptions{Region: "us"})) | ||
| _, err = client.SaveObjectsWithTransformation("index", []map[string]any{{"objectID": "1"}}) | ||
| require.Error(t, err) | ||
| require.NotContains(t, err.Error(), "TransformationOptions must be set") | ||
|
MarioAlexandruDan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| func TestWithTransformationOptionsFunctionalOption(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey", | ||
| search.WithTransformationOptions(search.TransformationOptions{ | ||
| Region: "us", | ||
| ReadTimeout: 50 * time.Second, | ||
| }), | ||
| ) | ||
| require.NoError(t, err) | ||
| _ = client | ||
| } | ||
|
|
||
| func TestSetTransformationOptionsReplacesTransporter(t *testing.T) { | ||
| client, err := search.NewClient("appID", "apiKey", | ||
| search.WithTransformationOptions(search.TransformationOptions{Region: "us"}), | ||
| ) | ||
| require.NoError(t, err) | ||
| // Replace with a different region — must not error | ||
| err = client.SetTransformationOptions(search.TransformationOptions{Region: "eu"}) | ||
| require.NoError(t, err) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.