Add mutex to table
This commit is contained in:
@@ -1,42 +1,46 @@
|
|||||||
package ramdb
|
package ramdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTable_NewIndex(t *testing.T) {
|
func TestTable_CreateIndex(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
test string
|
test string
|
||||||
table table
|
table table
|
||||||
onColumn string
|
column string
|
||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
test: "it should return ErrInvalidIndex if onColumn is empty",
|
test: "it should return ErrInvalidIndex if column is empty",
|
||||||
expectedError: ErrInvalidIndex,
|
expectedError: ErrInvalidIndex,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: "it should return ErrIndexExists if an index exists for onColumn",
|
test: "it should return ErrIndexExists if an index exists for column",
|
||||||
table: table{indexes: map[string]*index{
|
table: table{
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
|
indexes: map[string]*index{
|
||||||
"test_column": &index{},
|
"test_column": &index{},
|
||||||
}},
|
}},
|
||||||
onColumn: "test_column",
|
column: "test_column",
|
||||||
expectedError: ErrIndexExists,
|
expectedError: ErrIndexExists,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: "it should create an index successfully",
|
test: "it should create an index successfully",
|
||||||
table: table{
|
table: table{
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
indexes: make(map[string]*index),
|
indexes: make(map[string]*index),
|
||||||
},
|
},
|
||||||
onColumn: "test_column",
|
column: "test_column",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.test, func(t *testing.T) {
|
t.Run(tc.test, func(t *testing.T) {
|
||||||
err := tc.table.CreateIndex(tc.onColumn)
|
err := tc.table.CreateIndex(tc.column)
|
||||||
|
|
||||||
assert.Equal(t, tc.expectedError, err)
|
assert.Equal(t, tc.expectedError, err)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user