From be0ff7c4af04c82ec0108e3f5ad6998fe191b4db Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Wed, 25 Oct 2017 11:40:02 +0300 Subject: [PATCH] Added TLS support for running tests; CI runs tests with both http and https --- .travis.yml | 8 ++++++-- client_it_test.go | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 250a27b..2151590 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,14 @@ go: sudo: required group: deprecated-2017Q2 before_install: + - openssl req -x509 -newkey rsa:4096 -keyout test.pilosa.local.key -out test.pilosa.local.crt -days 3650 -nodes -subj "/C=US/ST=Texas/L=Austin/O=Pilosa/OU=Com/CN=test.pilosa.local" - wget https://s3.amazonaws.com/build.pilosa.com/pilosa-master-linux-amd64.tar.gz && tar xf pilosa-master-linux-amd64.tar.gz - - ./pilosa-master-linux-amd64/pilosa server & + - ./pilosa-master-linux-amd64/pilosa server -d http_data & + - ./pilosa-master-linux-amd64/pilosa server -b https://:20101 -d https_data --tls.skip-verify --tls.certificate test.pilosa.local.crt --tls.key test.pilosa.local.key & - go get github.com/mattn/goveralls - go get -u github.com/golang/dep/cmd/dep addons: script: - - dep ensure && $HOME/gopath/bin/goveralls -service=travis-ci -ignore "gopilosa_pbuf/public.pb.go" -flags="-tags=integration fullcoverage" + - dep ensure + - PILOSA_BIND="https://:20101" make test-all + - $HOME/gopath/bin/goveralls -service=travis-ci -ignore "gopilosa_pbuf/public.pb.go" -flags="-tags=integration fullcoverage" diff --git a/client_it_test.go b/client_it_test.go index 83fa8da..71ff8f8 100644 --- a/client_it_test.go +++ b/client_it_test.go @@ -36,6 +36,7 @@ package pilosa import ( "bytes" + "crypto/tls" "errors" "io" "net/http" @@ -47,7 +48,6 @@ import ( "testing" "time" - "crypto/tls" "github.com/golang/protobuf/proto" pbuf "github.com/pilosa/go-pilosa/gopilosa_pbuf" ) @@ -1371,7 +1371,7 @@ func TestStatusToNodeSlicesForIndex(t *testing.T) { } func getClient() *Client { - uri, err := NewURIFromAddress("http://:10101") + uri, err := NewURIFromAddress(getPilosaBindAddress()) if err != nil { panic(err) } @@ -1379,6 +1379,16 @@ func getClient() *Client { return NewClientWithCluster(cluster, &ClientOptions{TLSConfig: &tls.Config{InsecureSkipVerify: true}}) } +func getPilosaBindAddress() string { + for _, kvStr := range os.Environ() { + kv := strings.SplitN(kvStr, "=", 2) + if kv[0] == "PILOSA_BIND" { + return kv[1] + } + } + return "http://:10101" +} + func getMockServer(statusCode int, response []byte, contentLength int) *httptest.Server { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/x-protobuf")