Exemplo n.º 1
0
func TestS3Store(t *testing.T) {
	var store chainstore.Store
	var err error

	ctx := context.Background()

	assert := assert.New(t)

	store = chainstore.New(New(bucketID, accessKey, secretKey))
	err = store.Open()
	assert.Nil(err)
	defer store.Close()

	// Put a bunch of objects
	e1 := store.Put(ctx, "hi", []byte{1, 2, 3})
	e2 := store.Put(ctx, "bye", []byte{4, 5, 6})
	assert.Nil(e1)
	assert.Nil(e2)

	// Get those objects
	v1, _ := store.Get(ctx, "hi")
	v2, _ := store.Get(ctx, "bye")
	assert.Equal(v1, []byte{1, 2, 3})
	assert.Equal(v2, []byte{4, 5, 6})

	// Delete those objects
	e1 = store.Del(ctx, "hi")
	e2 = store.Del(ctx, "bye")
	assert.Equal(e1, nil)
	assert.Equal(e2, nil)
}
Exemplo n.º 2
0
func TestMetricsMgrStore(t *testing.T) {
	var store chainstore.Store
	var err error

	ctx := context.Background()

	assert := assert.New(t)

	store = chainstore.New(New("ns"))
	err = store.Open()
	assert.Nil(err)
	defer store.Close()

	// Put a bunch of objects
	e1 := store.Put(ctx, "hi", []byte{1, 2, 3})
	e2 := store.Put(ctx, "bye", []byte{4, 5, 6})
	assert.Nil(e1)
	assert.Nil(e2)

	// Delete those objects
	e1 = store.Del(ctx, "hi")
	e2 = store.Del(ctx, "bye")
	assert.Equal(e1, nil)
	assert.Equal(e2, nil)
}
Exemplo n.º 3
0
func TestBoltStore(t *testing.T) {
	var store chainstore.Store
	var err error

	store = boltstore.New(chainstore.TempDir()+"/test.db", "test")
	err = store.Open()
	if err != nil {
		t.Error(err)
	}
	defer store.Close() // does this get called?

	Convey("Boltdb Open", t, func() {

		Convey("Put a bunch of objects", func() {
			e1 := store.Put("hi", []byte{1, 2, 3})
			e2 := store.Put("bye", []byte{4, 5, 6})
			So(e1, ShouldEqual, nil)
			So(e2, ShouldEqual, nil)
		})

		Convey("Get those objects", func() {
			v1, _ := store.Get("hi")
			v2, _ := store.Get("bye")
			So(v1, ShouldResemble, []byte{1, 2, 3})
			So(v2, ShouldResemble, []byte{4, 5, 6})
		})

		Convey("Delete those objects", func() {
			e1 := store.Del("hi")
			e2 := store.Del("bye")
			So(e1, ShouldEqual, nil)
			So(e2, ShouldEqual, nil)

			v, _ := store.Get("hi")
			So(len(v), ShouldEqual, 0)
		})

	})
}
Exemplo n.º 4
0
func TestBoltStore(t *testing.T) {
	var store chainstore.Store
	var err error

	ctx := context.Background()

	store = chainstore.New(New(tempDir()+"/test.db", "test"))

	assert := assert.New(t)

	err = store.Open()
	assert.Nil(err)

	defer store.Close() // does this get called?

	// Put a bunch of objects
	e1 := store.Put(ctx, "hi", []byte{1, 2, 3})
	e2 := store.Put(ctx, "bye", []byte{4, 5, 6})
	assert.Equal(e1, nil)
	assert.Equal(e2, nil)

	// Get those objects
	v1, _ := store.Get(ctx, "hi")
	v2, _ := store.Get(ctx, "bye")
	assert.Equal(v1, []byte{1, 2, 3})
	assert.Equal(v2, []byte{4, 5, 6})

	// Delete those objects
	e1 = store.Del(ctx, "hi")
	e2 = store.Del(ctx, "bye")
	assert.Equal(e1, nil)
	assert.Equal(e2, nil)

	v, _ := store.Get(ctx, "hi")
	assert.Equal(len(v), 0)

}
Exemplo n.º 5
0
func TestLevelStore(t *testing.T) {
	var store chainstore.Store
	var err error

	store = levelstore.New(chainstore.TempDir())
	err = store.Open()
	if err != nil {
		t.Error(err)
	}
	defer store.Close()

	Convey("Leveldb Open", t, func() {

		Convey("Put a bunch of objects", func() {
			e1 := store.Put("hi", []byte{1, 2, 3})
			e2 := store.Put("bye", []byte{4, 5, 6})
			So(e1, ShouldEqual, nil)
			So(e2, ShouldEqual, nil)
		})

		Convey("Get those objects", func() {
			v1, _ := store.Get("hi")
			v2, _ := store.Get("bye")
			So(v1, ShouldResemble, []byte{1, 2, 3})
			So(v2, ShouldResemble, []byte{4, 5, 6})
		})

		Convey("Delete those objects", func() {
			e1 := store.Del("hi")
			e2 := store.Del("bye")
			So(e1, ShouldEqual, nil)
			So(e2, ShouldEqual, nil)
		})

	})
}