featurebase/index_test.go
Ben Johnson 54db22c54e bulk importer
This commit adds the pilosactl binary with a single `import` command.
The import allows users to bulk import data from a CSV file.
2016-01-02 15:10:17 -07:00

46 lines
1,013 B
Go

package pilosa_test
import (
"io/ioutil"
"os"
"github.com/umbel/pilosa"
)
// Index is a test wrapper for pilosa.Index.
type Index struct {
*pilosa.Index
}
// NewIndex returns a new instance of Index with a temporary path.
func NewIndex() *Index {
path, err := ioutil.TempDir("", "pilosa-")
if err != nil {
panic(err)
}
return &Index{Index: pilosa.NewIndex(path)}
}
// MustOpenIndex creates and opens an index at a temporary path. Panic on error.
func MustOpenIndex() *Index {
i := NewIndex()
if err := i.Open(); err != nil {
panic(err)
}
return i
}
// Close closes the index and removes all underlying data.
func (i *Index) Close() error {
defer os.RemoveAll(i.Path())
return i.Index.Close()
}
// MustCreateFragmentIfNotExists returns a given fragment. Panic on error.
func (i *Index) MustCreateFragmentIfNotExists(db, frame string, slice uint64) *Fragment {
f, err := i.Index.CreateFragmentIfNotExists(db, frame, slice)
if err != nil {
panic(err)
}
return &Fragment{Fragment: f}
}