Skip to content

Commit

Permalink
Merge pull request #7 from SierraSoftworks/refactor/testengine
Browse files Browse the repository at this point in the history
refactor: Rewrite all tests on top of testify and the standard library
  • Loading branch information
spartan563 authored Sep 25, 2019
2 parents fd33901 + f1381a5 commit 4b7f152
Show file tree
Hide file tree
Showing 45 changed files with 2,063 additions and 2,719 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ to those versions.
are performing active development against `sentry-go`.
- [**sentry-go.v1**](https://gopkg.in/SierraSoftworks/sentry-go.v1) - `import ("gopkg.in/SierraSoftworks/sentry-go.v1")`

This version of `sentry-go` maintains API compatibility with the package's v1 API. If you used
`sentry-go` for a project prior to 2019-09-25 then this is the version you should retain until
you can update your code. It will receive bug and security fixes.

- [**sentry-go.v2**](https://gopkg.in/SierraSoftworks/sentry-go.v2) - `import ("gopkg.in/SierraSoftworks/sentry-go.v2")`

This version is the most recent release of `sentry-go` and will maintain API compatibility. If you
are creating a project that relies on `sentry-go` then this is the version you should use.

Expand All @@ -46,7 +52,7 @@ package main
import (
"fmt"

"gopkg.in/SierraSoftworks/sentry-go.v1"
"gopkg.in/SierraSoftworks/sentry-go.v2"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -78,7 +84,7 @@ import (
"net/http"
"os"

"gopkg.in/SierraSoftworks/sentry-go.v1"
"gopkg.in/SierraSoftworks/sentry-go.v2"
)

func main() {
Expand Down Expand Up @@ -130,7 +136,7 @@ between different clients to impose custom behaviour for different portions
of your application.

```go
import "gopkg.in/SierraSoftworks/sentry-go.v1"
import "gopkg.in/SierraSoftworks/sentry-go.v2"

func main() {
// Configure a new global send queue
Expand Down
151 changes: 53 additions & 98 deletions breadcrumb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
)

func ExampleBreadcrumb() {
Expand Down Expand Up @@ -32,104 +32,59 @@ func ExampleBreadcrumb() {
}

func TestBreadcrumb(t *testing.T) {
Convey("Breadcrumb", t, func() {
data := map[string]interface{}{
"test": true,
data := map[string]interface{}{
"test": true,
}

t.Run("newBreadcrumb", func(t *testing.T) {
b := newBreadcrumb("default", data)

if assert.NotNil(t, b) {
assert.Implements(t, (*Breadcrumb)(nil), b)
assert.Equal(t, "", b.Type, "It should set the correct type")
assert.NotEqual(t, 0, b.Timestamp, "It should set the timestamp")
assert.Equal(t, data, b.Data, "It should set the correct data")
}
})

t.Run("WithMessage()", func(t *testing.T) {
b := newBreadcrumb("default", data)

if assert.NotNil(t, b) {
bb := b.WithMessage("test")
assert.Equal(t, b, bb, "It should return the breadcrumb for chaining")
assert.Equal(t, "test", b.Message)
}
})

t.Run("WithCategory()", func(t *testing.T) {
b := newBreadcrumb("default", data)

Convey("newBreadcrumb", func() {

Convey("Should return a Breadcrumb type", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)

So(b, ShouldImplement, (*Breadcrumb)(nil))
})

Convey("Should set the timestamp", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)
So(b.Timestamp, ShouldNotEqual, 0)
})

Convey("Should set the data", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)
So(b.Data, ShouldEqual, data)
})

Convey("Should set the Type correctly", func() {
Convey("With default type", func() {
b := newBreadcrumb("default", data)

So(b, ShouldNotBeNil)
So(b.Type, ShouldEqual, "")
})

Convey("With non-default type", func() {
b := newBreadcrumb("test", data)

So(b, ShouldNotBeNil)
So(b.Type, ShouldEqual, "test")
})
})
})

Convey("WithMessage()", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)

Convey("Should update the Message field", func() {
b.WithMessage("test")
So(b.Message, ShouldEqual, "test")
})

Convey("Should be chainable", func() {
So(b.WithMessage("test"), ShouldEqual, b)
})
})

Convey("WithCategory()", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)

Convey("Should update the Category field", func() {
b.WithCategory("test")
So(b.Category, ShouldEqual, "test")
})

Convey("Should be chainable", func() {
So(b.WithCategory("test"), ShouldEqual, b)
})
})

Convey("WithLevel()", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)

Convey("Should update the Level field", func() {
b.WithLevel(Error)
So(b.Level, ShouldEqual, Error)
})

Convey("Should be chainable", func() {
So(b.WithLevel(Error), ShouldEqual, b)
})
})

Convey("WithTimestamp()", func() {
b := newBreadcrumb("default", data)
So(b, ShouldNotBeNil)

Convey("Should update the Timestamp field", func() {
now := time.Now()
b.WithTimestamp(now)
So(b.Timestamp, ShouldEqual, now.UTC().Unix())
})

Convey("Should be chainable", func() {
So(b.WithTimestamp(time.Now()), ShouldEqual, b)
})
})
if assert.NotNil(t, b) {
bb := b.WithCategory("test")
assert.Equal(t, b, bb, "It should return the breadcrumb for chaining")
assert.Equal(t, "test", b.Category)
}
})

t.Run("WithLevel()", func(t *testing.T) {
b := newBreadcrumb("default", data)

if assert.NotNil(t, b) {
bb := b.WithLevel(Error)
assert.Equal(t, b, bb, "It should return the breadcrumb for chaining")
assert.Equal(t, Error, b.Level)
}
})

t.Run("WithTimestamp()", func(t *testing.T) {
b := newBreadcrumb("default", data)
now := time.Now()

if assert.NotNil(t, b) {
bb := b.WithTimestamp(now)
assert.Equal(t, b, bb, "It should return the breadcrumb for chaining")
assert.Equal(t, now.UTC().Unix(), b.Timestamp)
}
})
}
Loading

0 comments on commit 4b7f152

Please sign in to comment.