示例#1
0
func TestClose(t *testing.T) {
	err := c.Close()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = connPool.Close("1", "0")
	if err != nil && !e.Equal(err, ErrSessNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = connPool.Close("0", "1")
	if err != nil && !e.Equal(err, ErrInstNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = connPool.Close("0", "0")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = p.Close()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = server.Close()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#2
0
func TestDB(t *testing.T) {
	err := CreateDB(couchUrl, dbName)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	defer DeleteDB(couchUrl, dbName)

	err = CreateDB(couchUrl, dbName)
	if err != nil && !e.Equal(err, ErrDbExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	info, err := InfoDB(couchUrl, dbName)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if info.Db_name != dbName || info.Doc_count != 0 {
		t.Fatal("samething wrong with the db")
	}

	err = DeleteDB(couchUrl, dbName)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	_, err = InfoDB(couchUrl, dbName)
	if err != nil && !e.Equal(err, ErrDbNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	err = DeleteDB(couchUrl, dbName)
	if err != nil && !e.Equal(err, ErrDbNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#3
0
func TestInitClones(t *testing.T) {
	connPool = &clones{
		Num:    1,
		MaxNum: 5,
	}
	err := connPool.Init()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	connPoolErr := &clones{
		Num:    0,
		MaxNum: 5,
	}
	err = connPoolErr.Init()
	if err != nil && !e.Equal(err, "number of clones invalid") {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("nil error")
	}

	connPoolErr = &clones{
		Num:    10,
		MaxNum: 5,
	}
	err = connPoolErr.Init()
	if err != nil && !e.Equal(err, "number of streams is greater than max") {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("nil error")
	}
}
示例#4
0
func TestNewNoValueInstance(t *testing.T) {
	owners := auth.NewPlainTextCredentials()
	err := owners.Add(&auth.PlainText{"id", "pass1234"})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	ownersWrong := auth.NewPlainTextCredentials()
	err = ownersWrong.Add(&auth.PlainText{"id2", "passssss"})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	err = instances.NewNoValueInstance("1", "321", owners)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.NewNoValueInstance("1", "111", ownersWrong)
	if err != nil && !e.Equal(err, ErrOwnerNotMatch) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
	err = instances.NewNoValueInstance("123", "1", owners)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.NewNoValueInstance("123", "1", owners)
	if err != nil && !e.Equal(err, ErrInstExists) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
}
示例#5
0
func TestGet(t *testing.T) {
	inst, err := instances.Get("1", "1")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if inst.Instance().Type() != reflect.TypeOf(&teststruct{}) {
		t.Fatal("get fail")
	}

	inst, err = instances.Get("1", "3")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if inst.Instance().Type() != reflect.TypeOf(&teststruct{}) {
		t.Fatal("get fail")
	}

	_, err = instances.Get("1", "1")
	if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	_, err = instances.Get("2", "2")
	if err != nil && !e.Equal(err, ErrSessionNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = instances.Get("1", "2")
	if err != nil && !e.Equal(err, ErrInstanceNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#6
0
func TestAuthSession(t *testing.T) {
	a := &auth.PlainText{"id3", "pass6969"}
	err := instances.AuthSession("sess", a)
	if err != nil && !e.Equal(err, ErrSessionNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}

	err = instances.AuthSession("1", a)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	err = instances.AuthSession("1", &auth.PlainText{"id3", "pass69222269"})
	if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
	err = instances.AuthSession("1", &auth.PlainText{"id4", "pass69222269"})
	if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
}
示例#7
0
func TestConstructFail(t *testing.T) {
	err := constructor.New(&struct3{}, func(count int) int {
		return 42
	})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = constructor.Construct(types.Name(&struct3{}), 0)
	if err != nil && !e.Equal(err, ErrInvReturn) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}

	err = constructor.Delete(types.Name(&struct3{}))
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	err = constructor.New(&struct3{}, func(count int) (int, int) {
		return 42, 69
	})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = constructor.Construct(types.Name(&struct3{}), 0)
	if err != nil && !e.Equal(err, ErrInvReturn) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
}
示例#8
0
func TestDeletePlainTextCredentials(t *testing.T) {
	ptc := NewPlainTextCredentials()

	pt1 := &PlainText{"id", "pass1234"}

	err := ptc.Add(pt1)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = ptc.Get("id")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = ptc.Delete("id")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = ptc.Delete("id")
	if err != nil && !e.Equal(err, ErrCredNotExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = ptc.Get("id")
	if err != nil && !e.Equal(err, ErrCredNotExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#9
0
func TestAddPlainTextCredentials(t *testing.T) {
	ptc := NewPlainTextCredentials()

	pt1 := &PlainText{"id", "pass1234"}
	pt1b := &PlainText{"id", "pass1234"}
	pt2 := &PlainText{"id2", "pass2345"}
	hash := &Hashed{"a", "b"}

	err := ptc.Add(pt1)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = ptc.Add(pt2)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = ptc.Add(pt1b)
	if err != nil && !e.Equal(err, ErrCredExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = ptc.Add(hash)
	if err != nil && !e.Equal(err, ErrNotComp) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#10
0
func TestDelete(t *testing.T) {
	err := instances.Delete("1", "3")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.Delete("1", "3")
	if err != nil && !e.Equal(err, ErrInstanceNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.Delete("2", "3")
	if err != nil && !e.Equal(err, ErrSessionNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#11
0
func TestClonesReturnFail(t *testing.T) {
	conn, err := connPool.Request(p, "0")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = connPool.Return("1", "0", conn)
	if err != nil && !e.Equal(err, ErrSessNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = connPool.Return("0", "1", conn)
	if err != nil && !e.Equal(err, ErrInstNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#12
0
func TestInit(t *testing.T) {
	var err error
	p, err = openSession("tcp", server.Address().String(), nil, "0", id, time.Second, 0)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	c = &clone{
		Num:     1,
		MaxNum:  5,
		Session: p,
	}
	err = c.Init("0")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	cerr := &clone{
		Num:     5,
		MaxNum:  1,
		Session: p,
	}
	err = cerr.Init("0")
	if err != nil && !e.Equal(err, "number of initial streams is greater than the maximun") {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("nil error")
	}
	cerr = &clone{
		Num:     0,
		MaxNum:  1,
		Session: p,
	}
	err = cerr.Init("0")
	if err != nil && !e.Equal(err, "number of clones invalid") {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("nil error")
	}
	cerr = &clone{
		Num:     1,
		MaxNum:  3,
		Session: nil,
	}
	err = cerr.Init("0")
	if err != nil && !e.Equal(err, "nil Session") {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("nil error")
	}
}
示例#13
0
func TestExportGet(t *testing.T) {
	owners := auth.NewPlainTextCredentials()
	err := owners.Add(&auth.PlainText{"id", "pass1234"})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.New("sess", "testexport", reflect.ValueOf(&TestExport{}), owners)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.Export("sess", "testexport", &ToExport{
		Method:    "TestRetval",
		RetvalPos: 0,
		Export: &Export{
			Client: &TestExportClient{},
		},
	})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = instances.ExportGet("sess", "testexport", "TestRetval", 0)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	_, err = instances.ExportGet("invalid sess", "testexport", "TestRetval", 0)
	if err != nil && !e.Equal(err, ErrSessionNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
	_, err = instances.ExportGet("sess", "testexport__", "TestRetval", 0)
	if err != nil && !e.Equal(err, ErrInstanceNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
	_, err = instances.ExportGet("sess", "testexport", "TestRetval__", 0)
	if err != nil && !e.Equal(err, ErrMethodNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
	_, err = instances.ExportGet("sess", "testexport", "TestRetval", 999)
	if err != nil && !e.Equal(err, ErrReturnValueNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
}
示例#14
0
func TestPurge(t *testing.T) {
	instances.PurgeAll()
	_, err := instances.Get("1", "1")
	if err != nil && !e.Equal(err, ErrSessionNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#15
0
func TestEditPlainTextCredentials(t *testing.T) {
	ptc := NewPlainTextCredentials()

	pt1 := &PlainText{"id", "pass1234"}

	err := ptc.Add(pt1)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	pt1b := &PlainText{"id", "pass2345"}

	err = ptc.Edit(pt1b)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	auth, err := ptc.Get("id")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if !auth.Auth(pt1b) {
		t.Fatal("auth not equal")
	}

	pt2 := &PlainText{"id2", "pass2345"}
	err = ptc.Edit(pt2)
	if err != nil && !e.Equal(err, ErrCredNotExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#16
0
文件: couch.go 项目: fcavani/monlite
// Delete deletes from database the id id with rev revision.
// If rev is empty Delete deletes the last revision.
func (c *Couch) Delete(id, rev string) (string, error) {
	if rev == "" {
		revision := new(idRev)
		err := c.Get(id, "", revision)
		if e.Equal(err, ErrCantGetDoc) {
			return "", e.Push(err, ErrDocDontExist)
		} else if err != nil {
			return "", e.Push(err, "not deleted")
		}
		rev = revision.Rev
	}
	rev = "rev=" + rev
	code, resp, err := c.delete(id, rev, nil)
	if err != nil && code == 404 {
		return "", e.Push(err, ErrDocDontExist)
	} else if err != nil {
		return "", e.Push(err, "not deleted")
	}
	if code != http.StatusOK && code != http.StatusAccepted {
		return "", e.New("can't delete the document, wrong code: %v", code)
	}
	dr := new(response)
	err = json.Unmarshal(resp, dr)
	if err != nil {
		return "", e.Push(e.Push(err, "can't desserialize returned data"), "can't put the document")
	}
	if !dr.Ok {
		return "", e.New("delete failed")
	}
	if dr.Id != id {
		return "", e.New("response with the wrong id")
	}
	return dr.Rev, nil
}
示例#17
0
文件: tags.go 项目: fcavani/tags
// MergeFromStringSlice merges a slice, unordered and unchecked, into a tags.
// Check all slice itens in the process.
func (t *Tags) MergeFromStringSlice(slice []string) error {
	for _, s := range slice {
		err := t.Add(s)
		if err != nil && !e.Equal(err, ErrTagExist) {
			return e.Forward(err)
		}
	}
	return nil
}
示例#18
0
func TestNewConst(t *testing.T) {
	err := constructor.New(&struct1{}, NewStruct1)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = constructor.New(&struct1{}, NewStruct1)
	if err != nil && !e.Equal(err, ErrConstExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
	err = constructor.New(&struct2{}, "string")
	if err != nil && !e.Equal(err, ErrConstIsntFn) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
}
示例#19
0
文件: tags.go 项目: fcavani/tags
// Merge merges two tags sets.
func (t *Tags) Merge(tags *Tags) error {
	a := *tags
	for _, tag := range a {
		err := t.Add(tag)
		if err != nil && !e.Equal(err, ErrTagExist) {
			return e.Forward(err)
		}
	}
	return nil
}
示例#20
0
func TestDeleteConstructor(t *testing.T) {
	err := constructor.Delete(types.Name(&struct1{}))
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = constructor.Delete(types.Name(&struct1{}))
	if err != nil && !e.Equal(err, ErrConstNotFound) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#21
0
文件: url.go 项目: fcavani/net
// OnlyHost returns the FQDN or the ip of the host in the url.
func OnlyHost(rawurl string) (string, error) {
	parsed, err := url.Parse(rawurl)
	if err != nil {
		return "", e.Forward(err)
	}
	host, _, err := utilNet.SplitHostPort(parsed.Host)
	if err != nil && !e.Equal(err, utilNet.ErrCantFindPort) {
		return "", e.Forward(err)
	}
	return host, nil
}
示例#22
0
func (c *client) Close() error {
	err := c.clones.Close(c.SessionName, c.InstanceName)
	if err != nil && !e.Equal(err, ErrSessNotFound) {
		return e.Forward(err)
	}
	err = c.session.Close()
	if err != nil {
		return e.Forward(err)
	}
	return nil
}
示例#23
0
文件: storemgo.go 项目: fcavani/log
func (t *txMongoDb) Del(key string) error {
	if !t.writeble {
		return e.New(ErrReadOnly)
	}
	err := t.c.Remove(bson.M{"key": key})
	if e.Equal(err, mgo.ErrNotFound) {
		return e.New(ErrKeyNotFound)
	} else if err != nil {
		return e.New(err)
	}
	return nil
}
示例#24
0
func TestServerIpv4mc(t *testing.T) {
	in, err := Discover(net.FlagMulticast)
	if e.Equal(err, ErrNoInt) {
		t.Log("No multicast capable interface, may be this is travis.cl. Skip the test.")
		return
	} else if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	server := &Server{}
	server.Name = "master"
	server.PrivateKey = MasterKey
	server.PubKeys = Keys
	server.Interface = in
	server.AddrVer = Ipv4
	server.Protocol = func(addr *net.UDPAddr, req *Request) (resp *Response, err error) {
		if string(req.Data) != "request" {
			return nil, e.New("protocol error")
		}
		t.Log(req)
		return &Response{
			Data: []byte("msg"),
		}, nil
	}
	err = server.Do()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	defer server.Close()

	client := &Client{}
	client.ServerName = "master"
	client.ServerKey = &MasterKey.PublicKey
	client.Name = "slave"
	client.PrivateKey = SlaveKey
	client.Interface = in
	client.AddrVer = Ipv4
	client.Port = server.Port
	client.Request = func(dst *net.UDPAddr) (*Request, error) {
		return &Request{
			Data: []byte("request"),
		}, nil
	}
	resp, err := client.Discover()
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if string(resp.Data) != "msg" {
		t.Fatal("received wrong message", string(resp.Data))
	}
	t.Log(resp)
}
示例#25
0
func (n *notafifo) Read(b []byte) (int, error) {
	n.lck.Lock()
	if n.closed {
		n.lck.Unlock()
		return 0, e.New(ErrFifoClosed)
	}
	n.lck.Unlock()
	read, err := n.read(b)
	if e.Equal(err, barrier.ErrClosedBarrier) {
		return 0, io.EOF
	}
	return read, e.Forward(err)
}
示例#26
0
func TestSimpleJob(t *testing.T) {
	j := 0
	job := NewSimple("test", 0, func() error {
		j++
		return e.New("error")
	})
	go job.Do()
	var err error
	job.Returns(&err)
	if !e.Equal(err, "error") {
		t.Fatal(err)
	}
}
示例#27
0
func TestPut(t *testing.T) {
	couch := NewCouch(couchUrl, dbName)
	err := CreateDB(couchUrl, dbName)
	if err != nil && !e.Equal(err, ErrDbExist) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	defer DeleteDB(couchUrl, dbName)
	for i := 0; i < 10; i++ {
		test := TestStruct{
			Id:   strconv.FormatInt(int64(i), 10),
			Data: i,
		}
		id, _, err := couch.Put(test)
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}
		if id != test.Id {
			t.Fatal("wrong id", id)
		}
	}
	di, err := InfoDB(couchUrl, dbName)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if di.Db_name != dbName {
		t.Fatal("wrong db name")
	}
	if di.Doc_count != 10 {
		t.Fatal("wrong document count", di.Doc_count)
	}
	test := TestStruct{
		Id:   "1",
		Data: 1,
	}
	_, _, err = couch.Put(test)
	if err != nil && !e.Equal(err, ErrDocConflict) {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#28
0
func TestClientFail(t *testing.T) {
	client := &Client{}
	client.ServerName = "master"
	client.ServerKey = &MasterKey.PublicKey
	client.Name = "slave"
	client.PrivateKey = SlaveKey
	client.Interface = ":)"
	client.AddrVer = Any
	client.Port = "6464"
	client.Request = func(dst *net.UDPAddr) (*Request, error) {
		return &Request{
			Data: []byte("request"),
		}, nil
	}
	_, err := client.Discover()
	if err != nil && !e.Equal(err, "none interface with this name") {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	client = &Client{}
	client.ServerName = "master"
	client.ServerKey = &MasterKey.PublicKey
	client.Name = "slave"
	client.PrivateKey = SlaveKey
	client.AddrVer = Any
	client.Port = "6465"
	client.Timeout = 1 * time.Second
	client.Deadline = 100 * time.Millisecond
	client.Request = func(dst *net.UDPAddr) (*Request, error) {
		return &Request{
			Data: []byte("request"),
		}, nil
	}
	_, err = client.Discover()
	if err != nil && !e.Equal(err, "can't find the server") {
		t.Fatal(e.Trace(e.Forward(err)))
	}
}
示例#29
0
文件: storetests.go 项目: fcavani/log
func readonly(t *testing.T, s Storer) {
	defer func() {
		if r := recover(); r != "" {
			if str, ok := r.(string); ok {
				if str != "not implemented" {
					t.Fatal(str)
				}
			}
		}
	}()
	err := s.Tx(false, func(tx Transaction) error {
		return tx.Put("none", &TestStruct{I: 0, Key: "0"})
	})
	if err != nil && !e.Equal(err, ErrReadOnly) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}

	err = s.Tx(false, func(tx Transaction) error {
		return tx.Del("none")
	})
	if err != nil && !e.Equal(err, ErrReadOnly) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}

	err = s.Tx(false, func(tx Transaction) error {
		c := tx.Cursor()
		return c.Del()
	})
	if err != nil && !e.Equal(err, ErrReadOnly) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("error is nil")
	}
}
示例#30
0
func TestNewChValueInstance(t *testing.T) {
	owners := auth.NewPlainTextCredentials()
	err := owners.Add(&auth.PlainText{"id", "pass1234"})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	ownersWrong := auth.NewPlainTextCredentials()
	err = ownersWrong.Add(&auth.PlainText{"id2", "passssss"})
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	ch := make(chan int)
	err = instances.NewChValueInstance("new", "1", reflect.ValueOf(ch), reflect.BothDir, owners)
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	err = instances.NewChValueInstance("new", "1", reflect.ValueOf(ch), reflect.BothDir, owners)
	if err != nil && !e.Equal(err, ErrInstExists) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}
	err = instances.NewChValueInstance("new", "2", reflect.ValueOf(ch), reflect.BothDir, ownersWrong)
	if err != nil && !e.Equal(err, ErrOwnerNotMatch) {
		t.Fatal(e.Trace(e.Forward(err)))
	} else if err == nil {
		t.Fatal("err is nil")
	}

	inst, err := instances.Get("new", "1")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}
	if inst.Instance().Type() != reflect.TypeOf(ch) {
		t.Fatal("get fail")
	}
}