forked from databricks/databricks-sql-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testserver.go
40 lines (29 loc) · 858 Bytes
/
testserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package dbsql
import (
"net/http"
"net/http/httptest"
"github.com/apache/thrift/lib/go/thrift"
"github.com/databricks/databricks-sql-go/internal/cli_service"
)
type thriftHandler struct {
processor thrift.TProcessor
inPfactory, outPfactory thrift.TProtocolFactory
}
func (h *thriftHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
thriftHandler := thrift.NewThriftHandlerFunc(h.processor, h.inPfactory, h.outPfactory)
thriftHandler(w, r)
}
func initThriftTestServer(handler cli_service.TCLIService) *httptest.Server {
tcfg := &thrift.TConfiguration{
TLSConfig: nil,
}
protocolFactory := thrift.NewTBinaryProtocolFactoryConf(tcfg)
processor := cli_service.NewTCLIServiceProcessor(handler)
th := thriftHandler{
processor,
protocolFactory,
protocolFactory,
}
ts := httptest.NewServer(&th)
return ts
}