✅ Improve test coverage
This commit is contained in:
parent
6f06adc37d
commit
d7de194a90
4 changed files with 75 additions and 0 deletions
1
app.go
1
app.go
|
|
@ -33,6 +33,7 @@ func NewApp(ver string, conf config.Config, db store.Store) (*App, error) {
|
||||||
app := App{
|
app := App{
|
||||||
version: ver,
|
version: ver,
|
||||||
conf: conf,
|
conf: conf,
|
||||||
|
storage: db,
|
||||||
}
|
}
|
||||||
|
|
||||||
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL())
|
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL())
|
||||||
|
|
|
||||||
25
app_test.go
25
app_test.go
|
|
@ -78,6 +78,31 @@ func TestService(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppStorage(t *testing.T) {
|
||||||
|
th := setupAppTest(t)
|
||||||
|
base := "http://localhost:1234/"
|
||||||
|
th.conf.EXPECT().BaseURL().Return(base).MinTimes(1)
|
||||||
|
th.conf.EXPECT().Name().Return("").AnyTimes()
|
||||||
|
a, er := NewApp("0.0.0.0", th.conf, th.store)
|
||||||
|
assert.NoError(t, er)
|
||||||
|
if assert.NotNil(t, a) {
|
||||||
|
assert.Equal(t, th.store, a.Storage())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppUser(t *testing.T) {
|
||||||
|
// TODO: Actually fill this out at some point
|
||||||
|
th := setupAppTest(t)
|
||||||
|
base := "http://localhost:1234/"
|
||||||
|
th.conf.EXPECT().BaseURL().Return(base).MinTimes(1)
|
||||||
|
th.conf.EXPECT().Name().Return("").AnyTimes()
|
||||||
|
a, er := NewApp("0.0.0.0", th.conf, th.store)
|
||||||
|
assert.NoError(t, er)
|
||||||
|
if assert.NotNil(t, a) {
|
||||||
|
assert.Zero(t, a.User())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStrings(t *testing.T) {
|
func TestStrings(t *testing.T) {
|
||||||
cases := [...]struct {
|
cases := [...]struct {
|
||||||
given string
|
given string
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -24,3 +25,40 @@ func TestValidEnvReturnsCorrect(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigBaseURL(t *testing.T) {
|
||||||
|
c := config{baseURL: "https://me.goodevilgenius.org"}
|
||||||
|
assert.Equal(t, c.baseURL, c.BaseURL())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigStoreName(t *testing.T) {
|
||||||
|
c := config{stores: stores{store: "cockroachdb"}}
|
||||||
|
assert.Equal(t, c.stores.store, c.StoreName())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStoresMissingStore(t *testing.T) {
|
||||||
|
ss := stores{}
|
||||||
|
st, er := ss.GetStore("cockroachdb")
|
||||||
|
assert.Nil(t, st)
|
||||||
|
assert.ErrorIs(t, er, ErrMissingStore)
|
||||||
|
}
|
||||||
|
|
||||||
|
var mockToml = `
|
||||||
|
[cockroachdb]
|
||||||
|
|
||||||
|
dsn = "cockroachdb://user:pass@127.0.0.1:26257/combluotion"
|
||||||
|
`
|
||||||
|
|
||||||
|
type mockConn struct {
|
||||||
|
CockroachDB toml.Primitive
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStoreMap(t *testing.T) {
|
||||||
|
var conn mockConn
|
||||||
|
md, _ := toml.Decode(mockToml, &conn)
|
||||||
|
st := store{"cockroachdb", conn.CockroachDB, md}
|
||||||
|
|
||||||
|
m, er := st.Map()
|
||||||
|
assert.NoError(t, er)
|
||||||
|
assert.Equal(t, "cockroachdb://user:pass@127.0.0.1:26257/combluotion", m["dsn"])
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
@ -92,3 +93,13 @@ func TestMakeStoreNoName(t *testing.T) {
|
||||||
assert.NotNil(t, s)
|
assert.NotNil(t, s)
|
||||||
assert.NoError(t, e)
|
assert.NoError(t, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMakeStoreConfError(t *testing.T) {
|
||||||
|
th := setupFactoryTest(t)
|
||||||
|
mockError := errors.New("leave me alone")
|
||||||
|
th.conf.EXPECT().Store("mock").Return(nil, mockError)
|
||||||
|
s, e := MakeStore("mock", th.conf)
|
||||||
|
assert.Zero(t, s)
|
||||||
|
assert.ErrorIs(t, e, mockError)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue