diff --git a/Makefile b/Makefile index df6f46f96..94fd3a880 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,6 @@ testall: check_go_env test .PHONY: testall setup: Jamstash-master - @which goconvey || (echo "Installing GoConvey" && GO111MODULE=off go get -u github.com/smartystreets/goconvey) @which wire || (echo "Installing Wire" && GO111MODULE=off go get -u github.com/google/wire/cmd/wire) @which go-bindata || (echo "Installing BinData" && GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...) @which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex) diff --git a/go.mod b/go.mod index c68be7fc4..5585c94d7 100644 --- a/go.mod +++ b/go.mod @@ -32,8 +32,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pressly/goose v2.6.0+incompatible github.com/sirupsen/logrus v1.5.0 - github.com/smartystreets/assertions v1.0.1 // indirect - github.com/smartystreets/goconvey v1.6.4 github.com/stretchr/testify v1.4.0 // indirect golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect diff --git a/go.sum b/go.sum index 5c9c738e9..84946618d 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,6 @@ github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= -github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= @@ -170,6 +168,7 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s= golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20200117065230-39095c1d176c h1:FodBYPZKH5tAN2O60HlglMwXGAeV/4k+NKbli79M/2c= golang.org/x/tools v0.0.0-20200117065230-39095c1d176c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/log/log_test.go b/log/log_test.go index 69f951a12..98d6bec02 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -6,105 +6,114 @@ import ( "net/http/httptest" "testing" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - . "github.com/smartystreets/goconvey/convey" ) func TestLog(t *testing.T) { + SetLevel(LevelInfo) + RegisterFailHandler(Fail) + RunSpecs(t, "Log Suite") +} - Convey("Test Logger", t, func() { - l, hook := test.NewNullLogger() +var _ = Describe("Logger", func() { + var l *logrus.Logger + var hook *test.Hook + + BeforeEach(func() { + l, hook = test.NewNullLogger() SetLevel(LevelInfo) SetDefaultLogger(l) + }) - Convey("Plain message", func() { + Context("Logging", func() { + It("logs a simple message", func() { Error("Simple Message") - So(hook.LastEntry().Message, ShouldEqual, "Simple Message") - So(hook.LastEntry().Data, ShouldBeEmpty) + Expect(hook.LastEntry().Message).To(Equal("Simple Message")) + Expect(hook.LastEntry().Data).To(BeEmpty()) }) - Convey("Passing nil as context", func() { + It("logs a message when context is nil", func() { Error(nil, "Simple Message") - So(hook.LastEntry().Message, ShouldEqual, "Simple Message") - So(hook.LastEntry().Data, ShouldBeEmpty) + Expect(hook.LastEntry().Message).To(Equal("Simple Message")) + Expect(hook.LastEntry().Data).To(BeEmpty()) }) - SkipConvey("Empty context", func() { + XIt("Empty context", func() { Error(context.Background(), "Simple Message") - So(hook.LastEntry().Message, ShouldEqual, "Simple Message") - So(hook.LastEntry().Data, ShouldBeEmpty) + Expect(hook.LastEntry().Message).To(Equal("Simple Message")) + Expect(hook.LastEntry().Data).To(BeEmpty()) }) - Convey("Message with two kv pairs", func() { + It("logs messages with two kv pairs", func() { Error("Simple Message", "key1", "value1", "key2", "value2") - So(hook.LastEntry().Message, ShouldEqual, "Simple Message") - So(hook.LastEntry().Data["key1"], ShouldEqual, "value1") - So(hook.LastEntry().Data["key2"], ShouldEqual, "value2") - So(hook.LastEntry().Data, ShouldHaveLength, 2) + Expect(hook.LastEntry().Message).To(Equal("Simple Message")) + Expect(hook.LastEntry().Data["key1"]).To(Equal("value1")) + Expect(hook.LastEntry().Data["key2"]).To(Equal("value2")) + Expect(hook.LastEntry().Data).To(HaveLen(2)) }) - Convey("Only error", func() { + It("logs error objects as simple messages", func() { Error(errors.New("error test")) - So(hook.LastEntry().Message, ShouldEqual, "error test") - So(hook.LastEntry().Data, ShouldBeEmpty) + Expect(hook.LastEntry().Message).To(Equal("error test")) + Expect(hook.LastEntry().Data).To(BeEmpty()) }) - Convey("Error as last argument", func() { + It("logs errors passed as last argument", func() { Error("Error scrobbling track", "id", 1, errors.New("some issue")) - So(hook.LastEntry().Message, ShouldEqual, "Error scrobbling track") - So(hook.LastEntry().Data["id"], ShouldEqual, 1) - So(hook.LastEntry().Data["error"], ShouldEqual, "some issue") - So(hook.LastEntry().Data, ShouldHaveLength, 2) + Expect(hook.LastEntry().Message).To(Equal("Error scrobbling track")) + Expect(hook.LastEntry().Data["id"]).To(Equal(1)) + Expect(hook.LastEntry().Data["error"]).To(Equal("some issue")) + Expect(hook.LastEntry().Data).To(HaveLen(2)) }) - Convey("Passing a request", func() { + It("can get data from the request's context", func() { ctx := NewContext(nil, "foo", "bar") req := httptest.NewRequest("get", "/", nil).WithContext(ctx) Error(req, "Simple Message", "key1", "value1") - So(hook.LastEntry().Message, ShouldEqual, "Simple Message") - So(hook.LastEntry().Data["foo"], ShouldEqual, "bar") - So(hook.LastEntry().Data["key1"], ShouldEqual, "value1") - So(hook.LastEntry().Data, ShouldHaveLength, 2) + + Expect(hook.LastEntry().Message).To(Equal("Simple Message")) + Expect(hook.LastEntry().Data["foo"]).To(Equal("bar")) + Expect(hook.LastEntry().Data["key1"]).To(Equal("value1")) + Expect(hook.LastEntry().Data).To(HaveLen(2)) }) - Convey("Skip if level is lower", func() { + It("does not log anything if level is lower", func() { SetLevel(LevelError) Info("Simple Message") - So(hook.LastEntry(), ShouldBeNil) + Expect(hook.LastEntry()).To(BeNil()) }) }) - Convey("Test extractLogger", t, func() { - Convey("It returns an error if the context is nil", func() { + Context("extractLogger", func() { + It("returns an error if the context is nil", func() { _, err := extractLogger(nil) - So(err, ShouldNotBeNil) + Expect(err).ToNot(BeNil()) }) - Convey("It returns an error if the context is a string", func() { + It("returns an error if the context is a string", func() { _, err := extractLogger("any msg") - So(err, ShouldNotBeNil) + Expect(err).ToNot(BeNil()) }) - Convey("It returns the logger from context if it has one", func() { + It("returns the logger from context if it has one", func() { logger := logrus.NewEntry(logrus.New()) ctx := context.Background() ctx = context.WithValue(ctx, "logger", logger) - l, err := extractLogger(ctx) - So(err, ShouldBeNil) - So(l, ShouldEqual, logger) + Expect(extractLogger(ctx)).To(Equal(logger)) }) - Convey("It returns the logger from request's context if it has one", func() { + It("returns the logger from request's context if it has one", func() { logger := logrus.NewEntry(logrus.New()) ctx := context.Background() ctx = context.WithValue(ctx, "logger", logger) req := httptest.NewRequest("get", "/", nil).WithContext(ctx) - l, err := extractLogger(req) - So(err, ShouldBeNil) - So(l, ShouldEqual, logger) + + Expect(extractLogger(req)).To(Equal(logger)) }) }) -} +})