From 0c6d5992d0116b1f85b2f1f86fe6eab268a12d43 Mon Sep 17 00:00:00 2001 From: Tugba Dartici Date: Thu, 16 Nov 2017 09:48:09 +0300 Subject: [PATCH 1/2] Server TLS function added on engine. --- engine.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engine.go b/engine.go index 703f635..d01bfa2 100644 --- a/engine.go +++ b/engine.go @@ -79,6 +79,11 @@ func (e *Engine) ListenAndServe(addr string) error { return http.ListenAndServe(addr, e.actualRouter) } +// ListenAndServeTLS serves the given engine with a specific address on HTTPs. +func (e *Engine) ListenAndServeTLS(addr, certFile, keyFile string) error { + return http.ListenAndServeTLS(addr, certFile, keyFile, e.actualRouter) +} + // Provide provides with "default" key func (e *Engine) Provide(value interface{}) { e.injector.Provide(value, "default") From c73e5dff79a54b5dfb3053c46a65bbb85346576b Mon Sep 17 00:00:00 2001 From: Tugba Dartici Date: Thu, 16 Nov 2017 13:21:34 +0300 Subject: [PATCH 2/2] test added for listenAndServe --- .travis.yml | 3 +++ engine_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.travis.yml b/.travis.yml index d0546a8..1abe267 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ go: - 1.9 - tip +before_script: + - openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem -subj '/CN=localhost' + script: - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls diff --git a/engine_test.go b/engine_test.go index d37b26d..3fd074f 100644 --- a/engine_test.go +++ b/engine_test.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "github.com/stretchr/testify/assert" + "time" ) type errorTester struct{} @@ -109,3 +110,24 @@ func TestEngineFileServe(t *testing.T) { assert.Equal(t, http.StatusNotFound, resp3.Code) } + +func TestEngineListenAndServe(t *testing.T) { + e := newEngineTest() + var err error + var errTLS error + + go func () { + err = e.ListenAndServe(":1234") + }() + + go func() { + errTLS = e.ListenAndServeTLS(":12345", "cert.pem", "key.pem") + }() + + + // wait for ListenAndServe to run + time.Sleep(time.Millisecond * 300) + + assert.NoError(t, err) + assert.NoError(t, errTLS) +} \ No newline at end of file