Skip to content

Commit

Permalink
Merge pull request #1 from maxatome/type-T
Browse files Browse the repository at this point in the history
Add testdeep.T type
  • Loading branch information
maxatome committed May 29, 2018
2 parents 079d39d + 160f7a2 commit 3a29f22
Show file tree
Hide file tree
Showing 8 changed files with 2,068 additions and 63 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,48 @@ exit status 1
FAIL github.com/maxatome/go-testdeep 0.006s
```

Using [`testdeep.T`](https://godoc.org/github.com/maxatome/go-testdeep#T)
type, `TestCreateRecord` can also be written as:

```go
import (
"testing"
td "github.com/maxatome/go-testdeep"
)

type Record struct {
Id uint64
Name string
Age int
CreatedAt time.Time
}

func CreateRecord(name string, age int) (*Record, error) {
...
}

func TestCreateRecord(tt *testing.T) {
t := td.NewT(tt)

before := time.Now()
record, err := CreateRecord("Bob", 23)

if t.Nil(err) {
t.Struct(record,
Record{
Name: "Bob",
Age: 23,
},
StructFields{
"Id": td.Not(uint64(0)),
"CreatedAt": td.Between(before, time.Now()),
},
"Newly created record")
}
}
```


## Installation

```sh
Expand Down Expand Up @@ -228,9 +270,44 @@ func TestCreateRecord(t *testing.T) {
}
```

Last, [`testing.T`](https://golang.org/pkg/testing/#T) can be encapsulated in
[`T`](https://godoc.org/github.com/maxatome/go-testdeep#T) type,
simplifying again the test:

```go
import (
"testing"
td "github.com/maxatome/go-testdeep"
)

...

func TestCreateRecord(tt *testing.T) {
t := td.NewT(tt)

before := time.Now()
record, err := CreateRecord()

if t.Nil(err) {
t.Struct(record,
Record{
Name: "Bob",
Age: 23,
},
StructFields{
Id: td.Not(0),
CreatedAt: td.Between(before, time.Now()),
},
"Newly created record")
}
}
```


## Available operators

See functions returning [`TestDeep` interface](https://godoc.org/github.com/maxatome/go-testdeep#TestDeep):

- [`All`](https://godoc.org/github.com/maxatome/go-testdeep#All)
all expected values have to match;
- [`Any`](https://godoc.org/github.com/maxatome/go-testdeep#Any)
Expand Down
4 changes: 2 additions & 2 deletions cmp_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// DO NOT EDIT!!! AUTOMATICALLY GENERATED!!!

package testdeep

// DO NOT EDIT!!! AUTOMATICALLY GENERATED!!!

import (
"testing"
"time"
Expand Down
4 changes: 2 additions & 2 deletions cmp_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// DO NOT EDIT!!! AUTOMATICALLY GENERATED!!!

package testdeep_test

// DO NOT EDIT!!! AUTOMATICALLY GENERATED!!!

import (
"bytes"
"errors"
Expand Down

0 comments on commit 3a29f22

Please sign in to comment.