-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Append query options to context instead of overwriting. (#860)
* Append query options to context instead of overwriting. * lint. * Address feedback. * Use asserts.
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,35 @@ | ||
package clickhouse | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContext(t *testing.T) { | ||
t.Run("call context multiple times making sure query options are persisted across calls", | ||
func(t *testing.T) { | ||
ctx := Context(context.Background(), WithQueryID("a")) | ||
ctx = Context(ctx, WithQuotaKey("b")) | ||
ctx = Context(ctx, WithSettings(Settings{ | ||
"c": "d", | ||
})) | ||
|
||
opts := queryOptions(ctx) | ||
assert.Equal(t, "a", opts.queryID) | ||
assert.Equal(t, "b", opts.quotaKey) | ||
assert.Equal(t, "d", opts.settings["c"]) | ||
}, | ||
) | ||
|
||
t.Run("call context multiple times making sure query options are persisted across calls", | ||
func(t *testing.T) { | ||
ctx := Context(context.Background(), WithQueryID("a")) | ||
ctx = Context(ctx, WithQueryID("b")) | ||
|
||
opts := queryOptions(ctx) | ||
assert.Equal(t, "b", opts.queryID) | ||
}, | ||
) | ||
} |