🤡 Use uber mock for mocks
This commit is contained in:
parent
c73dfc0d3a
commit
ecae0d5f83
11 changed files with 2306 additions and 144 deletions
26
app_test.go
26
app_test.go
|
|
@ -4,22 +4,31 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"codeberg.org/danjones000/combluotion/config"
|
||||
"codeberg.org/danjones000/combluotion/internal/testmocks"
|
||||
vocab "github.com/go-ap/activitypub"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"codeberg.org/danjones000/combluotion/config"
|
||||
storeMock "codeberg.org/danjones000/combluotion/internal/testmocks/store"
|
||||
)
|
||||
|
||||
func getStore(t *testing.T) *storeMock.MockStore {
|
||||
t.Helper()
|
||||
ctrl := gomock.NewController(t)
|
||||
return storeMock.NewMockStore(ctrl)
|
||||
}
|
||||
|
||||
func TestEmptyBaseURL(t *testing.T) {
|
||||
c := config.Config{}
|
||||
a, er := NewApp("0.0.0", c, testmocks.GetStore())
|
||||
a, er := NewApp("0.0.0", c, getStore(t))
|
||||
assert.Nil(t, a)
|
||||
assert.EqualError(t, er, "missing BaseURL")
|
||||
}
|
||||
|
||||
func TestDefaultEnvironment(t *testing.T) {
|
||||
store := getStore(t)
|
||||
c := config.Config{BaseURL: "http://localhost:1234/"}
|
||||
a, er := NewApp("0.0.0", c, testmocks.GetStore())
|
||||
a, er := NewApp("0.0.0", c, store)
|
||||
assert.NoError(t, er)
|
||||
if assert.NotNil(t, a) {
|
||||
assert.Equal(t, config.Dev, a.Environment())
|
||||
|
|
@ -40,8 +49,9 @@ func TestGivenEnvironment(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
t.Run(string(c.given), func(t *testing.T) {
|
||||
store := getStore(t)
|
||||
conf := config.Config{BaseURL: "http://localhost:1234/", Env: c.given}
|
||||
a, er := NewApp("0.0.0", conf, testmocks.GetStore())
|
||||
a, er := NewApp("0.0.0", conf, store)
|
||||
assert.NoError(t, er)
|
||||
if assert.NotNil(t, a) {
|
||||
assert.Equal(t, conf, a.Config())
|
||||
|
|
@ -52,9 +62,10 @@ func TestGivenEnvironment(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestService(t *testing.T) {
|
||||
store := getStore(t)
|
||||
base := "http://localhost:1234/"
|
||||
conf := config.Config{BaseURL: base}
|
||||
a, er := NewApp("0.0.0.0", conf, testmocks.GetStore())
|
||||
a, er := NewApp("0.0.0.0", conf, store)
|
||||
assert.NoError(t, er)
|
||||
if assert.NotNil(t, a) {
|
||||
assert.Equal(t, vocab.IRI(base), a.ServiceIRI())
|
||||
|
|
@ -75,9 +86,10 @@ func TestStrings(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
t.Run(c.given, func(t *testing.T) {
|
||||
store := getStore(t)
|
||||
conf := config.Config{BaseURL: "http://localhost:1234/", Name: c.given}
|
||||
expStr := fmt.Sprintf("%s (%s)", c.exp, "0.0.0.0")
|
||||
a, er := NewApp("0.0.0.0", conf, testmocks.GetStore())
|
||||
a, er := NewApp("0.0.0.0", conf, store)
|
||||
assert.NoError(t, er)
|
||||
if assert.NotNil(t, a) {
|
||||
assert.Equal(t, c.exp, a.Name())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue