Пример #1
0
func TestCreatesDB(t *testing.T) {
	is := is.New(t)
	tmp := test.TempDir(is)
	defer test.DeleteDir(&tmp)

	db_path := tmp + "/c4.db"
	test_db, err := db.Open(db_path)
	is.NoErr(err)
	test_db.Close()
	if _, err = os.Stat(db_path); os.IsNotExist(err) {
		is.Fail("DB not created " + db_path)
	}
}
Пример #2
0
func TestPut(t *testing.T) {
	is := is.New(t)

	tmp := test.TempDir(is)
	defer test.DeleteDir(&tmp)

	db_path := tmp + "/c4.db"
	test_db, err := db.Open(db_path)
	is.NoErr(err)

	err = test_db.CreateBucket("bucket")
	is.NoErr(err)

	err = test_db.Put("bucket", []byte("key"), []byte("value: 42"))
	is.NoErr(err)
}
Пример #3
0
func TestCreatesBuckets(t *testing.T) {
	is := is.New(t)

	tmp := test.TempDir(is)
	defer test.DeleteDir(&tmp)

	db_path := tmp + "/c4.db"
	test_db, err := db.Open(db_path)
	is.NoErr(err)

	bucketsIn := []string{"bucket1", "bucket2", "bucket3"}

	err = test_db.CreateBuckets(bucketsIn)
	is.NoErr(err)

	bucketsOut, err := test_db.ListBuckets()
	is.NoErr(err)

	for i, bucket := range bucketsOut {
		is.Equal(bucket, bucketsIn[i])
	}

}
Пример #4
0
func TestItterate(t *testing.T) {
	is := is.New(t)

	tmp := test.TempDir(is)
	defer test.DeleteDir(&tmp)

	db_path := tmp + "/c4.db"
	test_db, err := db.Open(db_path)
	is.NoErr(err)

	err = test_db.CreateBucket("bucket")
	is.NoErr(err)

	keys := [][]byte{
		[]byte("key1"),
		[]byte("key2"),
	}
	values := [][]byte{
		[]byte("value: 42"),
		[]byte("value: 42, Oh no, not again."),
	}

	err = test_db.Put("bucket", keys[0], values[0])
	is.NoErr(err)

	err = test_db.Put("bucket", keys[1], values[1])
	is.NoErr(err)

	i := 0
	test_db.Iterate("bucket", func(k []byte, v []byte) bool {
		is.Equal(k, keys[i])
		is.Equal(v, values[i])
		i++
		return true
	})
}