From ee9b4dd519b57ede87eff735b3d63f71faf69fb9 Mon Sep 17 00:00:00 2001 From: thoeni Date: Tue, 5 Sep 2017 22:57:48 +0100 Subject: [PATCH] Update usage of go-tfl library Now the caller provides the `*http.Client` (timeout set to 5 seconds) --- Gopkg.lock | 16 ++++++++-------- Gopkg.toml | 2 +- http_handlers_test.go | 15 ++++++++------- main.go | 6 +++++- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 7ed9189..f401390 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -4,8 +4,8 @@ [[projects]] name = "github.com/aws/aws-sdk-go" packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/corehandlers","aws/credentials","aws/credentials/ec2rolecreds","aws/credentials/endpointcreds","aws/credentials/stscreds","aws/defaults","aws/ec2metadata","aws/endpoints","aws/request","aws/session","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/json/jsonutil","private/protocol/jsonrpc","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/xml/xmlutil","service/dynamodb","service/dynamodb/dynamodbattribute","service/sts"] - revision = "fdbcd18ca65c1deedcff224170b7d36f904f1c82" - version = "v1.10.26" + revision = "960dd6034cbdac0e9716bfa66d91de88b286889f" + version = "v1.10.38" [[projects]] branch = "master" @@ -41,7 +41,7 @@ branch = "master" name = "github.com/golang/protobuf" packages = ["proto"] - revision = "ab9f9a6dab164b7d1246e0e688b0ab7b94d8553e" + revision = "17ce1425424ab154092bbb43af630bd647f3bb0d" [[projects]] name = "github.com/gorilla/context" @@ -101,7 +101,7 @@ branch = "master" name = "github.com/prometheus/common" packages = ["expfmt","internal/bitbucket.org/ww/goautoneg","model"] - revision = "61f87aac8082fa8c3c5655c7608d7478d46ac2ad" + revision = "bc8b88226a1210b016e9993b1d75f858c9c8f778" [[projects]] branch = "master" @@ -122,20 +122,20 @@ version = "v1.1.4" [[projects]] - branch = "master" name = "github.com/thoeni/go-tfl" packages = ["."] - revision = "40993cc8bddf5f0ff75657e444108ce687beab9b" + revision = "b0eb28b16f49e3d44cb2c9d1114b94adbb161ec3" + version = "v1.0.0" [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix"] - revision = "9f7170bcd8e9f4d3691c06401119c46a769a1e03" + revision = "7ddbeae9ae08c6a06a59597f0c9edbc5ff2444ce" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "e152ac3ebafccfdc6b9de8484be969b0193b9c0d03d7ef169b0db3bda5da807b" + inputs-digest = "a3c025034949dad8b5b853548533d42720d67296c5f2ae2e1c539cb5dfbac7ec" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 5352e3d..7a5d68c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -58,5 +58,5 @@ version = "1.1.4" [[constraint]] - branch = "master" name = "github.com/thoeni/go-tfl" + version = "v1.0.0" diff --git a/http_handlers_test.go b/http_handlers_test.go index 09e0b20..a58d56b 100644 --- a/http_handlers_test.go +++ b/http_handlers_test.go @@ -3,15 +3,16 @@ package main import ( "bytes" "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" + "github.com/golang/mock/gomock" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/thoeni/go-tfl" "github.com/thoeni/slack-tube-service/mocks" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" ) const ( @@ -112,7 +113,7 @@ func TestLineStatusHandler_Integration_HappyPathAllLines(t *testing.T) { })) defer ts.Close() - cachedTflClient := tfl.NewCachedClient(120) + cachedTflClient := tfl.NewCachedClient(http.DefaultClient, 120) cachedTflClient.SetBaseURL(ts.URL + "/") tubeService = TubeService{cachedTflClient} @@ -137,10 +138,10 @@ func TestLineStatusHandler_Integration_HappyPathSingleLine(t *testing.T) { })) defer ts.Close() - client := tfl.NewClient() + client := tfl.NewClient(http.DefaultClient) client.SetBaseURL(ts.URL + "/") - cachedTflClient := tfl.NewCachedClient(120) + cachedTflClient := tfl.NewCachedClient(http.DefaultClient, 120) cachedTflClient.SetBaseURL(ts.URL + "/") tubeService = TubeService{cachedTflClient} diff --git a/main.go b/main.go index 52b11c3..f0a83e3 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "time" "flag" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" @@ -57,7 +58,10 @@ var ( ) ) -var tubeService TflService = TubeService{tfl.NewCachedClient(120)} +var httpTimeout = 5 * time.Second +var tubeService TflService = TubeService{ + tfl.NewCachedClient(&http.Client{Timeout: httpTimeout}, 120), +} func initialise() {