Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix broken build; add tests for go-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jan 15, 2019
1 parent f1d0c9f commit b4ee02e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

. "github.com/kamilsk/passport/pkg/config"
"github.com/kamilsk/passport/pkg/draft"
"github.com/stretchr/testify/assert"
yaml "gopkg.in/yaml.v2"
)
Expand Down
45 changes: 45 additions & 0 deletions pkg/draft/go-kit_test.go
@@ -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) })
})
}
}

0 comments on commit b4ee02e

Please sign in to comment.