Exemple #1
0
import (
	"bytes"
	"io"
	"os"
	"testing"

	"github.com/chzyer/fsmq/fsmq/util/test"
)

var (
	b *Instance
	_ io.ReaderAt = b
	_ io.WriterAt = b

	root = test.Root("/test/util/block")
)

func TestBlockException(t *testing.T) {
	defer test.New(t)

	_, err := New(root, 0, 33)
	test.NotNil(err)

	_, err = New("/notperm", 0, 11)
	test.NotNil(err)

	f, err := New(root, 0, 10)
	test.Nil(err)

	err = f.Delete(false)
Exemple #2
0
package fs

import (
	"encoding/binary"
	"fmt"
	"testing"
	"unsafe"

	"github.com/chzyer/fsmq/fsmq/util/qrand"
	"github.com/chzyer/fsmq/fsmq/util/test"
)

var root = test.Root("/test/fs/checkpoint")

func TestCheckSizeV1(t *testing.T) {
	defer test.New(t)
	s := SuperblockV1{}
	size := int(unsafe.Sizeof(s))
	test.Equal(size, ReserveBlockSize)

	size = int(unsafe.Sizeof(s) - unsafe.Sizeof(s.IndirectAddr))
	test.Equal(size, MetaSize)

	size = int(unsafe.Sizeof(InodeIndex{}))
	test.Equal(size, 32)

	maxRecordNum := len(s.IndirectAddr) * BlockSize / size
	test.Equal(maxRecordNum < 1<<20, false)
	test.Equal(maxRecordNum > 5<<20, false, fmt.Errorf("%v", maxRecordNum))
}
Exemple #3
0
package qio

import (
	"os"
	"testing"

	"github.com/chzyer/fsmq/fsmq/util/test"
)

var root = test.Root("/test/util/qio")

func TestReaderWriter(t *testing.T) {
	defer test.New(t)

	var n int
	f, err := os.Create(root)
	test.Nil(err)

	w := NewWriter(f, 1)
	offset, _ := w.Seek(-1, 1)
	test.NotEqual(offset, 0)

	_, err = w.Write([]byte("caoo"))
	test.Nil(err)
	defer w.Close()
	// |caoo

	_, err = w.Seek(0, 2)
	test.Equal(err, ErrSeekNotSupport)

	_, err = w.Seek(1, 0)