Exemplo n.º 1
0
func (s *S) TestObjectIdJSONUnmarshaling(c *C) {
	data := []byte(`{"Id":"4d88e15b60f486e428412dc9"}`)
	v := jsonType{}
	err := json.Unmarshal(data, &v)
	c.Assert(err, IsNil)
	c.Assert(*v.Id, Equals, bson.ObjectIdHex("4d88e15b60f486e428412dc9"))
}
Exemplo n.º 2
0
func (s *S) TestObjectIdJSONMarshaling(c *C) {
	id := bson.ObjectIdHex("4d88e15b60f486e428412dc9")
	v := jsonType{Id: &id}
	data, err := json.Marshal(&v)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, `{"Id":"4d88e15b60f486e428412dc9"}`)
}
Exemplo n.º 3
0
func (s *S) TestObjectIdHex(c *C) {
	id := bson.ObjectIdHex("4d88e15b60f486e428412dc9")
	c.Assert(id.String(), Equals, `ObjectIdHex("4d88e15b60f486e428412dc9")`)
	c.Assert(id.Hex(), Equals, "4d88e15b60f486e428412dc9")
}
Exemplo n.º 4
0
}

// --------------------------------------------------------------------------
// ObjectId parts extraction tests.

type objectIdParts struct {
	id        bson.ObjectId
	timestamp int64
	machine   []byte
	pid       uint16
	counter   int32
}

var objectIds = []objectIdParts{
	objectIdParts{
		bson.ObjectIdHex("4d88e15b60f486e428412dc9"),
		1300816219,
		[]byte{0x60, 0xf4, 0x86},
		0xe428,
		4271561,
	},
	objectIdParts{
		bson.ObjectIdHex("000000000000000000000000"),
		0,
		[]byte{0x00, 0x00, 0x00},
		0x0000,
		0,
	},
	objectIdParts{
		bson.ObjectIdHex("00000000aabbccddee000001"),
		0,