1//  Copyright (c) 2016 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package moss
16
17import (
18	"testing"
19
20	"github.com/blevesearch/bleve/index/store"
21	"github.com/blevesearch/bleve/index/store/test"
22)
23
24func open(t *testing.T, mo store.MergeOperator) store.KVStore {
25	rv, err := New(mo, nil)
26	if err != nil {
27		t.Fatal(err)
28	}
29	return rv
30}
31
32func cleanup(t *testing.T, s store.KVStore) {
33	err := s.Close()
34	if err != nil {
35		t.Fatal(err)
36	}
37}
38
39func TestMossKVCrud(t *testing.T) {
40	s := open(t, nil)
41	defer cleanup(t, s)
42	test.CommonTestKVCrud(t, s)
43}
44
45func TestMossReaderIsolation(t *testing.T) {
46	s := open(t, nil)
47	defer cleanup(t, s)
48	test.CommonTestReaderIsolation(t, s)
49}
50
51func TestMossReaderOwnsGetBytes(t *testing.T) {
52	s := open(t, nil)
53	defer cleanup(t, s)
54	test.CommonTestReaderOwnsGetBytes(t, s)
55}
56
57func TestMossWriterOwnsBytes(t *testing.T) {
58	s := open(t, nil)
59	defer cleanup(t, s)
60	test.CommonTestWriterOwnsBytes(t, s)
61}
62
63func TestMossPrefixIterator(t *testing.T) {
64	s := open(t, nil)
65	defer cleanup(t, s)
66	test.CommonTestPrefixIterator(t, s)
67}
68
69func TestMossPrefixIteratorSeek(t *testing.T) {
70	s := open(t, nil)
71	defer cleanup(t, s)
72	test.CommonTestPrefixIteratorSeek(t, s)
73}
74
75func TestMossRangeIterator(t *testing.T) {
76	s := open(t, nil)
77	defer cleanup(t, s)
78	test.CommonTestRangeIterator(t, s)
79}
80
81func TestMossRangeIteratorSeek(t *testing.T) {
82	s := open(t, nil)
83	defer cleanup(t, s)
84	test.CommonTestRangeIteratorSeek(t, s)
85}
86
87func TestMossMerge(t *testing.T) {
88	s := open(t, &test.TestMergeCounter{})
89	defer cleanup(t, s)
90	test.CommonTestMerge(t, s)
91}
92