Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql/driver"
"encoding/json"
"strings"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestCheckQueryID(t *testing.T) {
assert.True(t, ok, "Expected ContextKeyQueryID to be present in the context")

// Test case 2: Context already has ContextKeyQueryID
queryID := uuid.NewString()
queryID := strings.ReplaceAll(uuid.NewString(), "-", "")
ctxWithQueryID := context.WithValue(ctx, ContextKeyQueryID, queryID)
newCtxWithQueryID := checkQueryID(ctxWithQueryID)
assert.Equal(t, queryID, newCtxWithQueryID.Value(ContextKeyQueryID), "Expected ContextKeyQueryID to remain unchanged in the context")
Expand All @@ -64,7 +65,7 @@ func TestMakeHeadersQueryID(t *testing.T) {
tenant: "default",
sessionState: &SessionState{Role: "role1"},
}
queryId := uuid.NewString()
queryId := strings.ReplaceAll(uuid.NewString(), "-", "")
ctx := context.WithValue(context.Background(), ContextKeyQueryID, queryId)
headers, err := c.makeHeaders(ctx)
assert.Nil(t, err)
Expand Down
3 changes: 2 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"strings"
"sync/atomic"

"github.com/google/uuid"
Expand Down Expand Up @@ -192,7 +193,7 @@ func (dc *DatabendConn) ExecuteBatch() (err error) {
// checkQueryID checks if query_id exists in context, if not, generate a new one
func checkQueryID(ctx context.Context) context.Context {
if _, ok := ctx.Value(ContextKeyQueryID).(string); !ok {
queryId := uuid.NewString()
queryId := strings.ReplaceAll(uuid.NewString(), "-", "")
ctx = context.WithValue(ctx, ContextKeyQueryID, queryId)
}
return ctx
Expand Down