Live video on the AT Protocol
1package statedb 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "stream.place/streamplace/pkg/config" 8 "stream.place/streamplace/pkg/model" 9) 10 11// run the inner testing function against all databases we support 12func WithAllDatabases(t *testing.T, f func(*StatefulDB)) { 13 t.Run("sqlite", func(t *testing.T) { 14 cli := config.CLI{ 15 DBURL: ":memory:", 16 } 17 mod, err := model.MakeDB(":memory:") 18 require.NoError(t, err) 19 state, err := MakeDB(t.Context(), &cli, nil, mod) 20 require.NoError(t, err) 21 f(state) 22 }) 23 if postgresURL == "" { 24 t.Log("no postgres url, skipping postgres tests") 25 return 26 } else { 27 t.Run("postgres", func(t *testing.T) { 28 dburl := makePostgresURL(t) 29 cli := config.CLI{ 30 DBURL: dburl, 31 } 32 mod, err := model.MakeDB(":memory:") 33 require.NoError(t, err) 34 state, err := MakeDB(t.Context(), &cli, nil, mod) 35 require.NoError(t, err) 36 f(state) 37 sqlDB, err := state.DB.DB() 38 require.NoError(t, err) 39 40 // Close 41 sqlDB.Close() 42 }) 43 } 44}