Skip to content

Commit 090c469

Browse files
committed
Merge v2-unstable into v2.
2 parents 29cc868 + 9a2573d commit 090c469

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+15085
-639
lines changed

.travis.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
language: go
2+
3+
go_import_path: gopkg.in/mgo.v2-unstable
4+
5+
addons:
6+
apt:
7+
packages:
8+
9+
env:
10+
global:
11+
- BUCKET=https://niemeyer.s3.amazonaws.com
12+
matrix:
13+
- GO=1.4.1 MONGODB=x86_64-2.2.7
14+
- GO=1.4.1 MONGODB=x86_64-2.4.14
15+
- GO=1.4.1 MONGODB=x86_64-2.6.11
16+
- GO=1.4.1 MONGODB=x86_64-3.0.9
17+
- GO=1.4.1 MONGODB=x86_64-3.2.3-nojournal
18+
- GO=1.5.3 MONGODB=x86_64-3.0.9
19+
- GO=1.6 MONGODB=x86_64-3.0.9
20+
21+
install:
22+
- eval "$(gimme $GO)"
23+
24+
- wget $BUCKET/mongodb-linux-$MONGODB.tgz
25+
- tar xzvf mongodb-linux-$MONGODB.tgz
26+
- export PATH=$PWD/mongodb-linux-$MONGODB/bin:$PATH
27+
28+
- wget $BUCKET/daemontools.tar.gz
29+
- tar xzvf daemontools.tar.gz
30+
- export PATH=$PWD/daemontools:$PATH
31+
32+
- go get gopkg.in/check.v1
33+
- go get gopkg.in/yaml.v2
34+
- go get gopkg.in/tomb.v2
35+
36+
before_script:
37+
- export NOIPV6=1
38+
- make startdb
39+
40+
script:
41+
- (cd bson && go test -check.v)
42+
- go test -check.v -fast
43+
- (cd txn && go test -check.v)
44+
45+
# vim:sw=4:ts=4:et

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
startdb:
2-
@testdb/setup.sh start
2+
@harness/setup.sh start
33

44
stopdb:
5-
@testdb/setup.sh stop
5+
@harness/setup.sh stop

auth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ func (s *S) TestAuthX509Cred(c *C) {
904904
c.Skip("server does not support SSL")
905905
}
906906

907-
clientCertPEM, err := ioutil.ReadFile("testdb/client.pem")
907+
clientCertPEM, err := ioutil.ReadFile("harness/certs/client.pem")
908908
c.Assert(err, IsNil)
909909

910910
clientCert, err := tls.X509KeyPair(clientCertPEM, clientCertPEM)

bson/bson.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"crypto/rand"
3939
"encoding/binary"
4040
"encoding/hex"
41+
"encoding/json"
4142
"errors"
4243
"fmt"
4344
"io"
@@ -204,6 +205,7 @@ func readRandomUint32() uint32 {
204205
// machineId stores machine id generated once and used in subsequent calls
205206
// to NewObjectId function.
206207
var machineId = readMachineId()
208+
var processId = os.Getpid()
207209

208210
// readMachineId generates and returns a machine id.
209211
// If this function fails to get the hostname it will cause a runtime error.
@@ -234,9 +236,8 @@ func NewObjectId() ObjectId {
234236
b[5] = machineId[1]
235237
b[6] = machineId[2]
236238
// Pid, 2 bytes, specs don't specify endianness, but we use big endian.
237-
pid := os.Getpid()
238-
b[7] = byte(pid >> 8)
239-
b[8] = byte(pid)
239+
b[7] = byte(processId >> 8)
240+
b[8] = byte(processId)
240241
// Increment, 3 bytes, big endian
241242
i := atomic.AddUint32(&objectIdCounter, 1)
242243
b[9] = byte(i >> 16)
@@ -276,6 +277,22 @@ var nullBytes = []byte("null")
276277

277278
// UnmarshalJSON turns *bson.ObjectId into a json.Unmarshaller.
278279
func (id *ObjectId) UnmarshalJSON(data []byte) error {
280+
if len(data) > 0 && (data[0] == '{' || data[0] == 'O') {
281+
var v struct {
282+
Id json.RawMessage `json:"$oid"`
283+
Func struct {
284+
Id json.RawMessage
285+
} `json:"$oidFunc"`
286+
}
287+
err := jdec(data, &v)
288+
if err == nil {
289+
if len(v.Id) > 0 {
290+
data = []byte(v.Id)
291+
} else {
292+
data = []byte(v.Func.Id)
293+
}
294+
}
295+
}
279296
if len(data) == 2 && data[0] == '"' && data[1] == '"' || bytes.Equal(data, nullBytes) {
280297
*id = ""
281298
return nil

bson/bson_test.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func makeZeroDoc(value interface{}) (zero interface{}) {
7171
case reflect.Ptr:
7272
pv := reflect.New(v.Type().Elem())
7373
zero = pv.Interface()
74-
case reflect.Slice, reflect.Int:
74+
case reflect.Slice, reflect.Int, reflect.Int64, reflect.Struct:
7575
zero = reflect.New(t).Interface()
7676
default:
77-
panic("unsupported doc type")
77+
panic("unsupported doc type: " + t.Name())
7878
}
7979
return zero
8080
}
@@ -1055,7 +1055,7 @@ type inlineBadKeyMap struct {
10551055
}
10561056
type inlineUnexported struct {
10571057
M map[string]interface{} ",inline"
1058-
unexported ",inline"
1058+
unexported ",inline"
10591059
}
10601060
type unexported struct {
10611061
A int
@@ -1580,6 +1580,9 @@ func (s *S) TestObjectIdJSONMarshaling(c *C) {
15801580
}
15811581
}
15821582

1583+
// --------------------------------------------------------------------------
1584+
// Spec tests
1585+
15831586
type specTest struct {
15841587
Description string
15851588
Documents []struct {
@@ -1821,3 +1824,9 @@ func (s *S) BenchmarkUnmarshalRaw(c *C) {
18211824
panic(err)
18221825
}
18231826
}
1827+
1828+
func (s *S) BenchmarkNewObjectId(c *C) {
1829+
for i := 0; i < c.N; i++ {
1830+
bson.NewObjectId()
1831+
}
1832+
}

0 commit comments

Comments
 (0)