From b96ab9f753e7feb98c59ea4ced504651f7e56862 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 14 Nov 2016 16:03:46 -0500 Subject: [PATCH 1/3] Add test output to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8fde131..334490d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,10 @@ _cgo_gotypes.go _cgo_export.* _testmain.go +*.test *.exe # IntelliJ files .idea -*.iml \ No newline at end of file +*.iml From c7917be01e258eb5a57795cff50ff807f1056312 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 14 Nov 2016 16:23:11 -0500 Subject: [PATCH 2/3] Set up TLS for TestDefaultClientRejectSelfSigned In a previous commit we accidentally removed the setup of the TLS test suite which is used to verify the client behavior on self-signed TLS cert. This restores the correct behavior by splitting out a second test suite. previous ref 5642c3e463b246197f7019a0eaae2441b36843ef --- http/client_test.go | 13 ++++++++++--- testing/httpsuite_test.go | 9 ++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/http/client_test.go b/http/client_test.go index 55d2f7e..53c8d02 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -10,6 +10,7 @@ import ( httpsuite "github.com/joyent/gocommon/testing" "github.com/joyent/gosign/auth" + "github.com/julienschmidt/httprouter" ) const ( @@ -66,7 +67,7 @@ func (s *LoopingHTTPSuite) SetUpSuite(c *gc.C) { func (s *LoopingHTTPSuite) setupLoopbackRequest() (*http.Header, chan string, *Client) { var headers http.Header bodyChan := make(chan string, 1) - handler := func(resp http.ResponseWriter, req *http.Request) { + handler := func(resp http.ResponseWriter, req *http.Request, _ httprouter.Params) { headers = req.Header bodyBytes, _ := ioutil.ReadAll(req.Body) req.Body.Close() @@ -75,7 +76,7 @@ func (s *LoopingHTTPSuite) setupLoopbackRequest() (*http.Header, chan string, *C resp.WriteHeader(http.StatusNoContent) resp.Write([]byte{}) } - s.Mux.HandleFunc("/", handler) + s.Mux.POST("/", handler) client := New(s.creds, "", nil) return &headers, bodyChan, client @@ -89,8 +90,14 @@ type HTTPSClientTestSuite struct { LoopingHTTPSuite } +func newTLSsuite() *HTTPSClientTestSuite { + suite := &HTTPSClientTestSuite{} + suite.UseTLS = true + return suite +} + var _ = gc.Suite(&HTTPClientTestSuite{}) -var _ = gc.Suite(&HTTPSClientTestSuite{}) +var _ = gc.Suite(newTLSsuite()) func (s *HTTPClientTestSuite) assertHeaderValues(c *gc.C, apiVersion string) { emptyHeaders := http.Header{} diff --git a/testing/httpsuite_test.go b/testing/httpsuite_test.go index 60e31e1..c93e723 100644 --- a/testing/httpsuite_test.go +++ b/testing/httpsuite_test.go @@ -11,6 +11,7 @@ import ( "testing" jt "github.com/joyent/gocommon/testing" + "github.com/julienschmidt/httprouter" ) type HTTPTestSuite struct { @@ -28,16 +29,14 @@ func Test(t *testing.T) { var _ = gc.Suite(&HTTPTestSuite{}) var _ = gc.Suite(&HTTPSTestSuite{jt.HTTPSuite{UseTLS: true}}) -type HelloHandler struct{} - -func (h *HelloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func HelloHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(200) w.Write([]byte("Hello World\n")) } func (s *HTTPTestSuite) TestHelloWorld(c *gc.C) { - s.Mux.Handle("/", &HelloHandler{}) + s.Mux.GET("/", HelloHandler) response, err := http.Get(s.Server.URL) c.Check(err, gc.IsNil) content, err := ioutil.ReadAll(response.Body) @@ -49,7 +48,7 @@ func (s *HTTPTestSuite) TestHelloWorld(c *gc.C) { } func (s *HTTPSTestSuite) TestHelloWorldWithTLS(c *gc.C) { - s.Mux.Handle("/", &HelloHandler{}) + s.Mux.GET("/", HelloHandler) c.Check(s.Server.URL[:8], gc.Equals, "https://") response, err := http.Get(s.Server.URL) // Default http.Get fails because the cert is self-signed From c8c709ca2fbdfe6c682bd42784907cf48df31cfe Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 15 Nov 2016 15:25:12 -0500 Subject: [PATCH 3/3] Add support for Wercker CI --- README.md | 15 +++++++++++++++ errors/errors.go | 2 +- wercker.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 wercker.yml diff --git a/README.md b/README.md index df2d76d..d396b09 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ gocommon Common Go library for Joyent's Triton and Manta. +[![wercker status](https://app.wercker.com/status/2f63bf7f68bfdd46b979abad19c0bee0/s/master "wercker status")](https://app.wercker.com/project/byKey/2f63bf7f68bfdd46b979abad19c0bee0) + ## Installation Use `go-get` to install gocommon. @@ -70,7 +72,20 @@ upstream git@github.com:joyent/gocommon.git (push) ### Run Tests +The library needs values for the `SDC_URL`, `MANTA_URL`, `MANTA_KEY_ID` and `SDC_KEY_ID` environment variables even though the tests are run locally. You can generate a temporary key and use its fingerprint for tests without adding the key to your Triton Cloud account. + ``` +# create a temporary key +ssh-keygen -b 2048 -C "Testing Key" -f /tmp/id_rsa -t rsa -P "" + +# set up environment +# note: leave the -E md5 argument off on older ssh-keygen +export KEY_ID=$(ssh-keygen -E md5 -lf /tmp/id_rsa | awk -F' ' '{print $2}' | cut -d':' -f2-) +export SDC_KEY_ID=${KEY_ID} +export MANTA_KEY_ID=${KEY_ID} +export SDC_URL=https://us-east-1.api.joyent.com +export MANTA_URL=https://us-east.manta.joyent.com + cd ${GOPATH}/src/github.com/joyent/gocommon go test ./... ``` diff --git a/errors/errors.go b/errors/errors.go index f906e2c..4c641ca 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -29,7 +29,7 @@ const ( RequestTooLargeError = Code("RequestTooLarge") RequestMovedError = Code("RequestMoved") ResourceNotFoundError = Code("ResourceNotFound") - UnknownErrorError = Code("UnkownError") + UnknownErrorError = Code("UnknownError") ) // Error instances store an optional error cause. diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 0000000..563acf6 --- /dev/null +++ b/wercker.yml @@ -0,0 +1,40 @@ +box: golang + +build: + steps: + # Sets the go workspace and places you package + # at the right place in the workspace tree + - setup-go-workspace: + package-dir: github.com/joyent/gocommon + + # Gets the dependencies + - script: + name: go get + code: | + go get -v -t ./... + + # Build the project + - script: + name: go build + code: | + go build ./... + + - script: + name: make a new key for testing + code: | + ssh-keygen -b 2048 \ + -C "Testing Key" \ + -f /root/.ssh/id_rsa \ + -t rsa \ + -P "" + + # Test the project + - script: + name: go test + code: | + export KEY_ID=$(ssh-keygen -lf /root/.ssh/id_rsa | awk -F' ' '{print $2}' | cut -d':' -f2-) + export SDC_KEY_ID=${KEY_ID} + export MANTA_KEY_ID=${KEY_ID} + export SDC_URL=https://us-east-1.api.joyent.com + export MANTA_URL=https://us-east.manta.joyent.com + go test ./...