Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ostafen committed Sep 16, 2024
1 parent ede4626 commit 1379472
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/database/db_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/embedded/sql"
"github.com/codenotary/immudb/embedded/store"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -280,11 +281,18 @@ func TestLazyDB(t *testing.T) {
}, 1, logger)

dbList := NewDatabaseList(m)
_, err = dbList.GetByIndex(0)
require.ErrorIs(t, err, ErrDatabaseNotExists)

db := dbList.Put("testdb", DefaultOptions().WithDBRootPath(dir))
db1 := dbList.Put("testdb1", DefaultOptions().WithDBRootPath(dir))
closedDB := dbList.PutClosed("closeddb", DefaultOptions().WithDBRootPath(dir))

require.True(t, m.Has("testdb"))
require.True(t, m.Has("testdb1"))
require.False(t, db.IsClosed())
require.False(t, db1.IsClosed())
require.True(t, closedDB.IsClosed())

t.Run("isActive", func(t *testing.T) {
require.False(t, m.IsActive(0))
Expand Down Expand Up @@ -316,6 +324,10 @@ func TestLazyDB(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, state, err)

s, err := db1.Size()
require.NoError(t, err)
require.NotZero(t, s)

_, err = db1.Set(context.Background(), &schema.SetRequest{
KVs: []*schema.KeyValue{
{
Expand All @@ -325,6 +337,16 @@ func TestLazyDB(t *testing.T) {
})
require.NoError(t, err)

err = db1.WaitForTx(context.Background(), 1, true)
require.NoError(t, err)

err = db1.WaitForIndexingUpto(context.Background(), 1)
require.NoError(t, err)

s1, err := db1.Size()
require.NoError(t, err)
require.Greater(t, s1, s)

state1, err := db1.CurrentState()
require.NoError(t, err)
require.NotEqual(t, state, state1)
Expand All @@ -337,6 +359,25 @@ func TestLazyDB(t *testing.T) {
require.False(t, m.IsActive(1))
})

t.Run("copy catalog", func(t *testing.T) {
_, err := db1.CopySQLCatalog(context.Background(), 1)
require.NoError(t, err)
})

t.Run("truncate", func(t *testing.T) {
err := db1.TruncateUptoTx(context.Background(), 1)
require.NoError(t, err)
})

t.Run("sql", func(t *testing.T) {
params, err := db.InferParameters(context.Background(), nil, "SELECT * FROM table1")
require.ErrorIs(t, err, sql.ErrTableDoesNotExist)
require.Nil(t, params)

_, err = db.SQLQueryAll(context.Background(), nil, &schema.SQLQueryRequest{Sql: "SELECT * FROM table1"})
require.ErrorIs(t, err, sql.ErrTableDoesNotExist)
})

t.Run("IsLoaded", func(t *testing.T) {
require.True(t, m.IsLoaded(0))
err = m.Close(0)
Expand Down

0 comments on commit 1379472

Please sign in to comment.