This repository has been archived by the owner on May 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix broken build; add tests for go-kit
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package draft_test | ||
|
||
import ( | ||
"errors" | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
. "github.com/kamilsk/passport/pkg/draft" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSequence(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
size int | ||
}{ | ||
{"constant", 5}, | ||
{"random", rand.New(rand.NewSource(time.Now().UnixNano())).Int()}, | ||
} | ||
for _, test := range tests { | ||
tc := test | ||
t.Run(test.name, func(t *testing.T) { | ||
assert.Len(t, Sequence(tc.size), tc.size) | ||
}) | ||
} | ||
} | ||
|
||
func TestSafe(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
action func() error | ||
closer func(error) | ||
}{ | ||
{"with error", func() error { return errors.New("error") }, func(err error) { assert.Error(t, err) }}, | ||
{"with panic", func() error { panic(errors.New("panic")) }, func(err error) { assert.Error(t, err) }}, | ||
{"without anything", func() error { return nil }, func(err error) { assert.NoError(t, err) }}, | ||
} | ||
for _, test := range tests { | ||
tc := test | ||
t.Run(test.name, func(t *testing.T) { | ||
assert.NotPanics(t, func() { Safe(tc.action, tc.closer) }) | ||
}) | ||
} | ||
} |