@@ -17,10 +17,12 @@ package rai
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "net/http"
20
21
"strings"
21
22
"testing"
22
23
"time"
23
24
25
+ "github.com/google/uuid"
24
26
"github.com/stretchr/testify/assert"
25
27
)
26
28
@@ -951,3 +953,45 @@ func TestTransactionAbort(t *testing.T) {
951
953
assert .Nil (t , err )
952
954
assert .Equal (t , "integrity constraint violation" , rsp .Transaction .AbortReason )
953
955
}
956
+
957
+ func TestXRequestId (t * testing.T ) {
958
+ query := `def output = 1 + 1`
959
+ inputs := make ([]interface {}, 0 )
960
+
961
+ tx := TransactionRequest {
962
+ Database : test .databaseName ,
963
+ Engine : test .engineName ,
964
+ Query : query ,
965
+ ReadOnly : true ,
966
+ Inputs : inputs ,
967
+ Tags : []string {o11yTag }}
968
+ var rsp * http.Response
969
+ err := test .client .request (http .MethodPost , PathTransactions , nil , nil , tx , & rsp )
970
+
971
+ // assert that the request id is set
972
+ assert .Nil (t , err )
973
+ assert .NotEmpty (t , rsp .Header .Get ("X-Request-Id" ))
974
+
975
+ // assert that the request id is returned in the response
976
+ xRequestId := uuid .New ().String ()
977
+ headers := map [string ]string {"X-Request-Id" : xRequestId }
978
+ err = test .client .request (http .MethodPost , PathTransactions , headers , nil , tx , & rsp )
979
+
980
+ assert .Nil (t , err )
981
+ assert .Equal (t , xRequestId , rsp .Header .Get ("X-Request-Id" ))
982
+
983
+ // assert that the request id is specified in the error
984
+ tx = TransactionRequest {
985
+ Database : test .databaseName ,
986
+ Engine : "fake-engine" ,
987
+ Query : query ,
988
+ ReadOnly : true ,
989
+ Inputs : inputs ,
990
+ Tags : []string {o11yTag }}
991
+ xRequestId = uuid .New ().String ()
992
+ headers = map [string ]string {"X-Request-Id" : xRequestId }
993
+ err = test .client .request (http .MethodPost , PathTransactions , headers , nil , tx , & rsp )
994
+
995
+ assert .NotNil (t , err )
996
+ assert .Contains (t , err .Error (), xRequestId )
997
+ }
0 commit comments