summaryrefslogtreecommitdiff
path: root/test/go
diff options
context:
space:
mode:
authorYuxuan 'fishy' Wang <yuxuan.wang@reddit.com>2021-08-26 11:04:27 -0700
committerYuxuan 'fishy' Wang <fishywang@gmail.com>2021-08-27 09:28:08 -0700
commit17373a3f357cc81ab03fd02c316ad66b9c5ea260 (patch)
tree4bcbd85f46ce2fc1cf35e93ea7c6d79f3f55074b /test/go
parentd53f056427a093f782c234d6dff85881cff0f5fb (diff)
downloadthrift-17373a3f357cc81ab03fd02c316ad66b9c5ea260.tar.gz
go: Fix things staticcheck complains about
Client: go Staticcheck is the recommended replacement of the frozen and deprecated official golint linter [1]. Fix the things it complained about (or add lint:ignore directive) in: - lib/go/thrift - lib/go/test/tests - tutorial/go/src - test/go/src - compiler generated code The majority of the fixes are in the following categories: - Use of deprecated function (mainly the TConfiguration related ones) - Redundant break in switch cases - Unused and unexported variables/fields/functions Also in the same spirit as fb539ae, remove the error return from NewTSSLSocket as it can never be non-nil. This change will be cherry-picked into 0.15.0 branch after merged. [1]: https://groups.google.com/g/golang-nuts/c/rCP70Aq_tBc
Diffstat (limited to 'test/go')
-rw-r--r--test/go/src/bin/stress/main.go6
-rw-r--r--test/go/src/bin/testclient/main.go4
-rw-r--r--test/go/src/bin/testserver/main.go1
-rw-r--r--test/go/src/common/client.go33
-rw-r--r--test/go/src/common/clientserver_test.go4
-rw-r--r--test/go/src/common/context_test.go3
-rw-r--r--test/go/src/common/printing_handler.go2
-rw-r--r--test/go/src/common/server.go21
-rw-r--r--test/go/src/common/simple_handler.go3
9 files changed, 44 insertions, 33 deletions
diff --git a/test/go/src/bin/stress/main.go b/test/go/src/bin/stress/main.go
index 9f3267654..3273d1bbe 100644
--- a/test/go/src/bin/stress/main.go
+++ b/test/go/src/bin/stress/main.go
@@ -103,14 +103,14 @@ func main() {
var transportFactory thrift.TTransportFactory
if *compact {
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(nil)
} else {
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil)
}
if *framed {
transportFactory = thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
} else {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
}
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 39ee95b0d..f0ce0528e 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -36,7 +36,6 @@ var domain_socket = flag.String("domain-socket", "", "Domain Socket (e.g. /tmp/t
var transport = flag.String("transport", "buffered", "Transport: buffered, framed, http, zlib")
var protocol = flag.String("protocol", "binary", "Protocol: binary, compact, json")
var ssl = flag.Bool("ssl", false, "Encrypted Transport using SSL")
-var zlib = flag.Bool("zlib", false, "Wrapped Transport using Zlib")
var testloops = flag.Int("testloops", 1, "Number of Tests")
func main() {
@@ -131,6 +130,9 @@ func callEverything(client *thrifttest.ThriftTestClient) {
binout[i] = byte(i)
}
bin, err := client.TestBinary(defaultCtx, binout)
+ if err != nil {
+ t.Fatalf("TestBinary failed with %v", err)
+ }
for i := 0; i < 256; i++ {
if binout[i] != bin[i] {
t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
diff --git a/test/go/src/bin/testserver/main.go b/test/go/src/bin/testserver/main.go
index d4bd8b4f5..011a71d48 100644
--- a/test/go/src/bin/testserver/main.go
+++ b/test/go/src/bin/testserver/main.go
@@ -35,7 +35,6 @@ var domain_socket = flag.String("domain-socket", "", "Domain Socket (e.g. /tmp/T
var transport = flag.String("transport", "buffered", "Transport: buffered, framed, http, zlib")
var protocol = flag.String("protocol", "binary", "Protocol: binary, compact, json, header")
var ssl = flag.Bool("ssl", false, "Encrypted Transport using SSL")
-var zlib = flag.Bool("zlib", false, "Wrapped Transport using Zlib")
var certPath = flag.String("certPath", "keys", "Directory that contains SSL certificates")
func main() {
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index 201503538..f9dfcaf6b 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -42,32 +42,35 @@ func StartClient(
domain_socket string,
transport string,
protocol string,
- ssl bool) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
-
+ ssl bool,
+) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
hostPort := fmt.Sprintf("%s:%d", host, port)
+ cfg := &thrift.TConfiguration{
+ TLSConfig: &tls.Config{
+ InsecureSkipVerify: true,
+ },
+ }
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)
case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
+ protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg)
case "header":
- protocolFactory = thrift.NewTHeaderProtocolFactory()
+ protocolFactory = thrift.NewTHeaderProtocolFactoryConf(cfg)
default:
- return nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, nil, fmt.Errorf("invalid protocol specified %s", protocol)
}
if debugClientProtocol {
protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "client:", thrift.StdLogger(nil))
}
if ssl {
- trans, err = thrift.NewTSSLSocketConf(hostPort, &thrift.TConfiguration{
- TLSConfig: &tls.Config{InsecureSkipVerify: true},
- })
+ trans = thrift.NewTSSLSocketConf(hostPort, cfg)
} else {
if domain_socket != "" {
trans = thrift.NewTSocketConf(domain_socket, nil)
@@ -85,21 +88,21 @@ func StartClient(
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
- trans, err = thrift.NewTHttpPostClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
+ trans, err = thrift.NewTHttpClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
fmt.Println(hostPort)
} else {
- trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
+ trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/", hostPort))
}
case "framed":
- trans = thrift.NewTFramedTransport(trans)
+ trans = thrift.NewTFramedTransportConf(trans, cfg)
case "buffered":
trans = thrift.NewTBufferedTransport(trans, 8192)
case "zlib":
trans, err = thrift.NewTZlibTransport(trans, zlib.BestCompression)
case "":
- trans = trans
+ // Do nothing
default:
- return nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
+ return nil, nil, fmt.Errorf("invalid transport specified %s", transport)
}
if err != nil {
return nil, nil, err
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index d5e3c4326..609086bad 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -49,7 +49,6 @@ var units = []test_unit{
}
func TestAllConnection(t *testing.T) {
- certPath = "../../../keys"
wg := &sync.WaitGroup{}
wg.Add(len(units))
for _, unit := range units {
@@ -67,6 +66,9 @@ func doUnit(t *testing.T, unit *test_unit) {
handler := NewMockThriftTest(ctrl)
processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+ if err != nil {
+ t.Errorf("GetServerParams failed: %v", err)
+ }
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
if err = server.Listen(); err != nil {
diff --git a/test/go/src/common/context_test.go b/test/go/src/common/context_test.go
index 3e21a5411..c6cbad8f6 100644
--- a/test/go/src/common/context_test.go
+++ b/test/go/src/common/context_test.go
@@ -40,8 +40,6 @@ func (slowHttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func TestHttpContextTimeout(t *testing.T) {
- certPath = "../../../keys"
-
unit := test_unit{"127.0.0.1", 9096, "", "http", "binary", false}
server := &http.Server{Addr: unit.host + fmt.Sprintf(":%d", unit.port), Handler: slowHttpHandler{}}
@@ -56,6 +54,7 @@ func TestHttpContextTimeout(t *testing.T) {
unwrapErr := func(err error) error {
for {
+ //lint:ignore S1034 type switch is more appropriate here.
switch err.(type) {
case thrift.TTransportException:
err = err.(thrift.TTransportException).Err()
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
index d91dde403..b726373fe 100644
--- a/test/go/src/common/printing_handler.go
+++ b/test/go/src/common/printing_handler.go
@@ -26,6 +26,7 @@ import (
"fmt"
"time"
+ //lint:ignore ST1001 allow dot import here
. "github.com/apache/thrift/test/go/src/gen/thrifttest"
)
@@ -333,6 +334,7 @@ func (p *printingHandler) TestException(ctx context.Context, arg string) (err er
e.Message = arg
return e
case "TException":
+ //lint:ignore ST1005 To be consistent with other language libraries.
return errors.New("Just TException")
}
return
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index 6e3a5d31b..f48389d44 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -31,7 +31,6 @@ import (
var (
debugServerProtocol bool
- certPath string
)
func init() {
@@ -46,28 +45,30 @@ func GetServerParams(
protocol string,
ssl bool,
certPath string,
- handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
+ handler thrifttest.ThriftTest,
+) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
var err error
hostPort := fmt.Sprintf("%s:%d", host, port)
+ var cfg *thrift.TConfiguration = nil
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)
case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
+ protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil)
case "header":
- protocolFactory = thrift.NewTHeaderProtocolFactory()
+ protocolFactory = thrift.NewTHeaderProtocolFactoryConf(nil)
default:
- return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, nil, nil, nil, fmt.Errorf("invalid protocol specified %s", protocol)
}
if debugServerProtocol {
- protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
+ protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "server:", thrift.StdLogger(nil))
}
var serverTransport thrift.TServerTransport
@@ -98,7 +99,7 @@ func GetServerParams(
transportFactory = nil
case "framed":
transportFactory = thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
case "buffered":
transportFactory = thrift.NewTBufferedTransportFactory(8192)
case "zlib":
@@ -106,7 +107,7 @@ func GetServerParams(
case "":
transportFactory = thrift.NewTTransportFactory()
default:
- return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
+ return nil, nil, nil, nil, fmt.Errorf("invalid transport specified %s", transport)
}
processor := thrifttest.NewThriftTestProcessor(handler)
diff --git a/test/go/src/common/simple_handler.go b/test/go/src/common/simple_handler.go
index 971f17eec..fb9545799 100644
--- a/test/go/src/common/simple_handler.go
+++ b/test/go/src/common/simple_handler.go
@@ -23,6 +23,7 @@ import (
"errors"
"time"
+ //lint:ignore ST1001 allow dot import here
. "github.com/apache/thrift/test/go/src/gen/thrifttest"
)
@@ -104,6 +105,7 @@ func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, er
}
func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
+ //lint:ignore ST1005 To be consistent with other language libraries.
return nil, errors.New("No Insanity")
}
@@ -125,6 +127,7 @@ func (p *simpleHandler) TestException(arg string) (err error) {
e.Message = arg
return e
case "TException":
+ //lint:ignore ST1005 To be consistent with other language libraries.
return errors.New("Just TException")
}
return