From 937a0cdf641aa66ba8cf413f684d67dc3a9fd90d Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 23 Mar 2018 14:14:10 -0700 Subject: Adding system test coverage support Added support for running system level code coverage tasks Updated sms.go to allow graceful shutdown when it gets a SIGINT. Useful for gather coverage information. Issue-ID: AAF-192 Change-Id: Ife4a485e7926fd59948bf90fac4b2d4ea9de0332 Signed-off-by: Kiran Kamineni --- sms-service/doc/coverage.html | 1182 +++++++++++++++++++++++++++++++++++++++ sms-service/src/sms/Gopkg.lock | 22 +- sms-service/src/sms/Gopkg.toml | 2 +- sms-service/src/sms/coverage.md | 41 ++ sms-service/src/sms/sms.go | 19 +- sms-service/src/sms/sms_test.go | 31 + 6 files changed, 1284 insertions(+), 13 deletions(-) create mode 100644 sms-service/doc/coverage.html create mode 100644 sms-service/src/sms/coverage.md create mode 100644 sms-service/src/sms/sms_test.go (limited to 'sms-service') diff --git a/sms-service/doc/coverage.html b/sms-service/doc/coverage.html new file mode 100644 index 0000000..d03ddde --- /dev/null +++ b/sms-service/doc/coverage.html @@ -0,0 +1,1182 @@ + + + + + + + + +
+ +
+ not tracked + + no coverage + low coverage + * + * + * + * + * + * + * + * + high coverage + +
+
+
+ + + + + + + + + + + + + + + +
+ + + diff --git a/sms-service/src/sms/Gopkg.lock b/sms-service/src/sms/Gopkg.lock index 12bdfab..b856a81 100644 --- a/sms-service/src/sms/Gopkg.lock +++ b/sms-service/src/sms/Gopkg.lock @@ -53,7 +53,7 @@ branch = "master" name = "github.com/hashicorp/go-uuid" packages = ["."] - revision = "64130c7a86d732268a38cb04cfbaf0cc987fda98" + revision = "27454136f0364f2d44b1276c552d69105cf8c498" [[projects]] branch = "master" @@ -69,7 +69,7 @@ "json/scanner", "json/token" ] - revision = "23c074d0eceb2b8a5bfdbb271ab780cde70f05a8" + revision = "f40e974e75af4e271d97ce0fc917af5898ae7bda" [[projects]] name = "github.com/hashicorp/vault" @@ -80,8 +80,8 @@ "helper/parseutil", "helper/strutil" ] - revision = "36edb4d42380d89a897e7f633046423240b710d9" - version = "v0.9.5" + revision = "7e1fbde40afee241f81ef08700e7987d86fc7242" + version = "v0.9.6" [[projects]] branch = "master" @@ -93,7 +93,7 @@ branch = "master" name = "github.com/mitchellh/mapstructure" packages = ["."] - revision = "b4575eea38cca1123ec2dc90c26529b5c5acfcff" + revision = "00c29f56e2386353d58c599509e8dc3801b0d716" [[projects]] name = "github.com/ryanuber/go-glob" @@ -105,7 +105,7 @@ branch = "master" name = "github.com/sethgrid/pester" packages = ["."] - revision = "760f8913c0483b776294e1bee43f1d687527127b" + revision = "ed9870dad3170c0b25ab9b11830cc57c3a7798fb" [[projects]] branch = "master" @@ -119,7 +119,7 @@ "openpgp/packet", "openpgp/s2k" ] - revision = "85f98707c97e11569271e4d9b3d397e079c4f4d0" + revision = "88942b9c40a4c9d203b82b3731787b672d6e809b" [[projects]] branch = "master" @@ -130,10 +130,9 @@ "idna", "lex/httplex" ] - revision = "0ed95abb35c445290478a5348a7b38bb154135fd" + revision = "6078986fec03a1dcc236c34816c71b0e05018fda" [[projects]] - branch = "master" name = "golang.org/x/text" packages = [ "collate", @@ -151,11 +150,12 @@ "unicode/norm", "unicode/rangetable" ] - revision = "e19ae1496984b1c655b8044a65c0300a3c878dd3" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "c3b1a2cc60523cdaccc247048d5e99d9b2f5c5f5e7f66c3e1deb9e709ec6f8bc" + inputs-digest = "5bf63627c88decba9287076c33fbda6ac39f0256039375b4002dc35db39c214f" solver-name = "gps-cdcl" solver-version = 1 diff --git a/sms-service/src/sms/Gopkg.toml b/sms-service/src/sms/Gopkg.toml index f811086..cab4149 100644 --- a/sms-service/src/sms/Gopkg.toml +++ b/sms-service/src/sms/Gopkg.toml @@ -26,7 +26,7 @@ [[constraint]] name = "github.com/hashicorp/vault" - version = "0.9.4" + version = "0.9.5" [[constraint]] branch = "master" diff --git a/sms-service/src/sms/coverage.md b/sms-service/src/sms/coverage.md new file mode 100644 index 0000000..6168342 --- /dev/null +++ b/sms-service/src/sms/coverage.md @@ -0,0 +1,41 @@ +## Code Coverage Reports for Golang Applications ## + +This document covers how to generate HTML Code Coverage Reports for +Golang Applications. + +#### Generate a test executable which calls your main() + +```sh +$ go test -c -covermode=count -coverpkg ./... +``` + +#### Run the generated application to produce a new coverage report + +```sh +$ ./sms.test -test.run "^TestMain$" -test.coverprofile=coverage.cov +``` + +#### Run your unit tests to produce their coverage report + +```sh +$ go test -test.covermode=count -test.coverprofile=unit.out ./... +``` + +#### Merge the two coverage Reports + +```sh +$ go get github.com/wadey/gocovmerge +$ gocovmerge unit.out coverage.cov > all.out +``` + +#### Generate HTML Report + +```sh +$ go tool cover -html all.out -o coverage.html +``` + +#### Generate Function Report + +```sh +$ go tool cover -func all.out +``` \ No newline at end of file diff --git a/sms-service/src/sms/sms.go b/sms-service/src/sms/sms.go index eb0bebc..de9d0a7 100644 --- a/sms-service/src/sms/sms.go +++ b/sms-service/src/sms/sms.go @@ -17,8 +17,11 @@ package main import ( + "context" "log" "net/http" + "os" + "os/signal" smsauth "sms/auth" smsbackend "sms/backend" @@ -56,6 +59,20 @@ func main() { TLSConfig: tlsConfig, } + // Listener for SIGINT so that it returns cleanly + connectionsClose := make(chan struct{}) + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + <-c + httpServer.Shutdown(context.Background()) + close(connectionsClose) + }() + err = httpServer.ListenAndServeTLS(smsConf.ServerCert, smsConf.ServerKey) - log.Fatal(err) + if err != nil && err != http.ErrServerClosed { + log.Fatal(err) + } + + <-connectionsClose } diff --git a/sms-service/src/sms/sms_test.go b/sms-service/src/sms/sms_test.go new file mode 100644 index 0000000..35dce24 --- /dev/null +++ b/sms-service/src/sms/sms_test.go @@ -0,0 +1,31 @@ +/* + * Copyright 2018 Intel Corporation, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" + "testing" +) + +func TestMain(t *testing.T) { + fmt.Println(os.Args) + t.Log(os.Args) + if os.Args[0] == "./sms.test" { + main() + } +} -- cgit 1.2.3-korg