featurebase/frame_test.go
Ben Johnson b873b4c084 refactor attribute stores
This commit refactors the profile and bitmap attribute stores so
that they share the same code. There is a new `AttrStore` which
associates key/value pairs with a `uint64` identifier.

The previous JSON encoding has been fixed to use protobufs which
fixes encoding issues for int64.
2016-02-16 13:41:37 -07:00

65 lines
1.3 KiB
Go

package pilosa_test
import (
"io/ioutil"
"os"
"testing"
"github.com/umbel/pilosa"
)
// Ensure frame can open and retrieve a fragment.
func TestFrame_CreateFragmentIfNotExists(t *testing.T) {
f := MustOpenFrame()
defer f.Close()
// Create fragment.
frag, err := f.CreateFragmentIfNotExists(100)
if err != nil {
t.Fatal(err)
} else if frag == nil {
t.Fatal("expected fragment")
}
// Retrieve existing fragment.
frag2, err := f.CreateFragmentIfNotExists(100)
if err != nil {
t.Fatal(err)
} else if frag != frag2 {
t.Fatal("fragment mismatch")
}
if frag != f.Fragment(100) {
t.Fatal("fragment mismatch")
}
}
// Frame represents a test wrapper for pilosa.Frame.
type Frame struct {
*pilosa.Frame
}
// NewFrame returns a new instance of Frame d/0.
func NewFrame() *Frame {
path, err := ioutil.TempDir("", "pilosa-frame-")
if err != nil {
panic(err)
}
return &Frame{Frame: pilosa.NewFrame(path, "d", "f")}
}
// MustOpenFrame returns a new, opened frame at a temporary path. Panic on error.
func MustOpenFrame() *Frame {
f := NewFrame()
if err := f.Open(); err != nil {
panic(err)
}
return f
}
// Close closes the frame and removes the underlying data.
func (f *Frame) Close() error {
defer os.RemoveAll(f.Path())
return f.Frame.Close()
}