-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexer_test.go
50 lines (41 loc) · 1.21 KB
/
indexer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package indexer
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
const (
testName = "test"
testNameError = "error"
)
func TestIndexerInitOk(t *testing.T) {
indexer := NewIndexer()
indexer.CreateIndex(testName, reflect.TypeOf((*stringIndexElement)(nil)))
_, err := indexer.Index(testName)
assert.NoError(t, err)
}
func TestIndexerInitError(t *testing.T) {
indexer := NewIndexer()
indexer.CreateIndex(testName, reflect.TypeOf((*stringIndexElement)(nil)))
_, err := indexer.Index(testNameError)
assert.Error(t, err)
}
func TestIndexerDoubleCreateIndex(t *testing.T) {
indexer := NewIndexer()
in, err := indexer.CreateIndex(testName, reflect.TypeOf((*stringIndexElement)(nil)))
assert.Nil(t, err)
assert.NotNil(t, in)
in, err = indexer.CreateIndex(testName, reflect.TypeOf((*stringIndexElement)(nil)))
assert.Error(t, err)
assert.NotNil(t, in)
}
func TestIndexerDoubleDeleteIndex(t *testing.T) {
indexer := NewIndexer()
in, err := indexer.CreateIndex(testName, reflect.TypeOf((*stringIndexElement)(nil)))
assert.Nil(t, err)
assert.NotNil(t, in)
delete1 := indexer.DeleteIndex(testName)
assert.True(t, delete1)
delete2 := indexer.DeleteIndex(testName)
assert.False(t, delete2)
}