From 90b18daa64dd4f10ead3c26ceffd20797c56963d Mon Sep 17 00:00:00 2001 From: Kamil Samigullin Date: Mon, 24 Jun 2019 15:57:17 +0300 Subject: [PATCH] fix build for go 1.10 and go 1.11, add build and coverage badges --- .travis.yml | 2 -- README.md | 4 ++++ caller_test.go | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 790b0d4..e2005b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ language: go go: - master - 1.x -- 1.8.x -- 1.9.x - 1.10.x - 1.11.x - 1.12.x diff --git a/README.md b/README.md index b7d1c08..8dbf01c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ > > Simple, lightweight tracing mechanism. +[![Build][icon_build]][page_build] +[![Coverage][icon_coverage]][page_coverage] [![Documentation][icon_docs]][page_docs] ## 💡 Idea @@ -97,9 +99,11 @@ $ go get -u github.com/kamilsk/tracer made with ❤️ for everyone [icon_build]: https://travis-ci.org/kamilsk/tracer.svg?branch=master +[icon_coverage]: https://api.codeclimate.com/v1/badges/fb66449d1f5c64542377/test_coverage [icon_docs]: https://godoc.org/github.com/kamilsk/tracer?status.svg [page_build]: https://travis-ci.org/kamilsk/tracer +[page_coverage]: https://codeclimate.com/github/kamilsk/tracer/test_coverage [page_docs]: https://godoc.org/github.com/kamilsk/tracer [page_promo]: https://github.com/kamilsk/tracer diff --git a/caller_test.go b/caller_test.go index da4265d..522b95c 100644 --- a/caller_test.go +++ b/caller_test.go @@ -1,7 +1,7 @@ package tracer_test import ( - "reflect" + "strings" "testing" . "github.com/kamilsk/tracer" @@ -11,17 +11,28 @@ func TestCaller(t *testing.T) { tests := []struct { name string caller func() CallerInfo - expected string + expected []string }{ - {"direct caller", callerA, "github.com/kamilsk/tracer_test.callerA"}, - {"chain caller", callerB, "github.com/kamilsk/tracer_test.callerA"}, - {"lambda caller", callerC, "github.com/kamilsk/tracer_test.callerC"}, + {"direct caller", callerA, []string{"github.com/kamilsk/tracer_test.callerA"}}, + {"chain caller", callerB, []string{"github.com/kamilsk/tracer_test.callerA"}}, + {"lambda caller", callerC, []string{ + "github.com/kamilsk/tracer_test.callerC", + "github.com/kamilsk/tracer_test.callerC.func1", // Go 1.10, 1.11 - https://golang.org/doc/go1.12#runtime + }}, } for _, test := range tests { tc := test t.Run(test.name, func(t *testing.T) { - if expected, obtained := tc.expected, tc.caller().Name; !reflect.DeepEqual(tc.expected, obtained) { - t.Errorf("\n expected: %+#v \n obtained: %+#v", expected, obtained) + var found bool + obtained := tc.caller().Name + for _, expected := range tc.expected { + if expected == obtained { + found = true + break + } + } + if !found { + t.Errorf("\n expected: %+#v \n obtained: %+#v", strings.Join(tc.expected, " or "), obtained) } }) }