mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
datastore no longer implements logstore (#1013)
* datastore no longer implements logstore the underlying implementation of our sql store implements both the datastore and the logstore interface, however going forward we are likely to encounter datastore implementers that would mock out the logstore interface and not use its methods - signalling a poor interface. this remedies that, now they are 2 completely separate things, which our sqlstore happens to implement both of. related to some recent changes around wrapping, this keeps the imposed metrics and validation wrapping of a servers logstore and datastore, just moving it into New instead of in the opts - this is so that a user can have the underlying datastore in order to set the logstore to it, since wrapping it in a validator/metrics would render it no longer a logstore implementer (i.e. validate datastore doesn't implement the logstore interface), we need to do this after setting the logstore to the datastore if one wasn't provided explicitly. * splits logstore and datastore metrics & validation logic * `make test` should be `make full-test` always. got rid of that so that nobody else has to wait for CI to blow up on them after the tests pass locally ever again. * fix new tests
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
// * run all down migrations
|
||||
// * run all up migrations
|
||||
// [ then run tests against that db ]
|
||||
func newWithMigrations(ctx context.Context, url *url.URL) (*sqlStore, error) {
|
||||
func newWithMigrations(ctx context.Context, url *url.URL) (*SQLStore, error) {
|
||||
ds, err := newDS(ctx, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -49,16 +49,20 @@ func TestDatastore(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := func(t *testing.T) models.Datastore {
|
||||
f := func(t *testing.T) *SQLStore {
|
||||
os.RemoveAll("sqlite_test_dir")
|
||||
ds, err := newDS(ctx, u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// we don't want to test the validator, really
|
||||
return ds
|
||||
}
|
||||
f2 := func(t *testing.T) models.Datastore {
|
||||
ds := f(t)
|
||||
return datastoreutil.NewValidator(ds)
|
||||
}
|
||||
datastoretest.Test(t, f)
|
||||
datastoretest.Test(t, f2)
|
||||
|
||||
// also logs
|
||||
logstoretest.Test(t, f(t))
|
||||
@@ -72,7 +76,7 @@ func TestDatastore(t *testing.T) {
|
||||
// will down migrate all migrations, up migrate, and run tests again.
|
||||
|
||||
both := func(u *url.URL) {
|
||||
f := func(t *testing.T) models.Datastore {
|
||||
f := func(t *testing.T) *SQLStore {
|
||||
ds, err := newDS(ctx, u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -81,16 +85,20 @@ func TestDatastore(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return ds
|
||||
}
|
||||
f2 := func(t *testing.T) models.Datastore {
|
||||
ds := f(t)
|
||||
return datastoreutil.NewValidator(ds)
|
||||
}
|
||||
|
||||
// test fresh w/o migrations
|
||||
datastoretest.Test(t, f)
|
||||
datastoretest.Test(t, f2)
|
||||
|
||||
// also test sql implements logstore
|
||||
logstoretest.Test(t, f(t))
|
||||
|
||||
f = func(t *testing.T) models.Datastore {
|
||||
f = func(t *testing.T) *SQLStore {
|
||||
t.Log("with migrations now!")
|
||||
ds, err := newWithMigrations(ctx, u)
|
||||
if err != nil {
|
||||
@@ -100,11 +108,15 @@ func TestDatastore(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return ds
|
||||
}
|
||||
f2 = func(t *testing.T) models.Datastore {
|
||||
ds := f(t)
|
||||
return datastoreutil.NewValidator(ds)
|
||||
}
|
||||
|
||||
// test that migrations work & things work with them
|
||||
datastoretest.Test(t, f)
|
||||
datastoretest.Test(t, f2)
|
||||
|
||||
// also test sql implements logstore
|
||||
logstoretest.Test(t, f(t))
|
||||
|
||||
Reference in New Issue
Block a user