1//  Copyright (c) 2014 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 bleve
16
17import (
18	"os"
19	"testing"
20)
21
22func TestIndexMeta(t *testing.T) {
23	var testIndexPath = "doesnotexit.bleve"
24	defer func() {
25		err := os.RemoveAll(testIndexPath)
26		if err != nil {
27			t.Fatal(err)
28		}
29	}()
30
31	// open non-existent meta should give an error
32	_, err := openIndexMeta(testIndexPath)
33	if err == nil {
34		t.Errorf("expected error, got nil")
35	}
36
37	// create meta
38	im := &indexMeta{Storage: "boltdb"}
39	err = im.Save(testIndexPath)
40	if err != nil {
41		t.Error(err)
42	}
43	im = nil
44
45	// open a meta that exists
46	im, err = openIndexMeta(testIndexPath)
47	if err != nil {
48		t.Error(err)
49	}
50	if im.Storage != "boltdb" {
51		t.Errorf("expected storage 'boltdb', got '%s'", im.Storage)
52	}
53
54	// save a meta that already exists
55	err = im.Save(testIndexPath)
56	if err == nil {
57		t.Errorf("expected error, got nil")
58	}
59}
60