Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2b6402d
Add option to start DB test as Docker container
sebastien-rosset Mar 17, 2017
e54a350
add unit test
sebastien-rosset Mar 18, 2017
6c8a117
change go imports
sebastien-rosset Mar 18, 2017
512995d
change type to integer
sebastien-rosset Mar 18, 2017
94e118f
remove hostname and name arguments
sebastien-rosset Mar 18, 2017
c141f81
change import back to mgo.v2
sebastien-rosset Mar 18, 2017
c427782
specify mongo version in UT, verify running version matches requested…
sebastien-rosset Mar 18, 2017
0ed34a2
Invoke 'docker pull' before 'docker run' to avoid dial problems
sebastien-rosset Mar 24, 2017
039a978
Add debug statements
sebastien-rosset Mar 24, 2017
2eb6605
Allocate pseudo tty to address chown permission denied on some platforms
sebastien-rosset Mar 24, 2017
c757253
Invoke 'docker stop' to stop container when test has completed
sebastien-rosset Mar 31, 2017
99f3ecb
Invoke 'docker rm' to delete the container when test has completed
sebastien-rosset Mar 31, 2017
6d2e8d9
Set random seed to prevent container name collisions
sebastien-rosset Mar 31, 2017
8de861e
Run gofmt
sebastien-rosset Mar 31, 2017
45272df
Fix race condition on shutdown
sebastien-rosset Apr 10, 2017
0b38669
Add helper function to return the host name of the DB test instance. …
sebastien-rosset Apr 13, 2017
6439679
Add helper function to return the host name of the DB test instance. …
sebastien-rosset Apr 13, 2017
c67d9ad
Add helper function to return the host name of the DB test instance. …
sebastien-rosset Apr 13, 2017
163facc
Print MGO stats before panic
sebastien-rosset Apr 20, 2017
4f5053d
Split bulk update and remove operations to stay under limit.
kboreddy Jun 20, 2017
70c8959
CSCve54898 Add more debug info for tests
sebastien-rosset Jun 23, 2017
b1aa086
CSCve54898 Add more debug info for tests
sebastien-rosset Jun 23, 2017
6f135e7
CSCve54898 Add configurable timeout
sebastien-rosset Jun 25, 2017
3bc4928
CSCve54898 Add troubleshooting when mongo runs in a container
sebastien-rosset Jun 25, 2017
1e59200
Add log timestamp to help troubleshooting
sebastien-rosset Jun 26, 2017
41d7481
Add more debug for troubleshooting
sebastien-rosset Jun 27, 2017
f2b7ebf
Send 'docker' command output to stderr/stdout if debug is enabled
sebastien-rosset Aug 10, 2017
66ca93c
In case of failure, print list of containers running mongo
sebastien-rosset Aug 11, 2017
aa8ae44
Let docker assign host port
sebastien-rosset Aug 15, 2017
3986c5b
Let docker assign host port
sebastien-rosset Aug 15, 2017
1a4c45e
Let docker assign host port
sebastien-rosset Aug 15, 2017
34d4ed0
Let docker assign host port
sebastien-rosset Aug 15, 2017
eb71381
Let docker assign host port
sebastien-rosset Aug 16, 2017
9bbc623
Add retry loop when pulling mongo image
sebastien-rosset Sep 19, 2017
a90f58c
Add print statement for debugging
sebastien-rosset Sep 19, 2017
9ba021d
Add print statement for debugging
sebastien-rosset Sep 19, 2017
9af84a5
Print log statement when skipping Wipe()
sebastien-rosset Sep 26, 2017
26872c5
Print log statement when skipping Wipe()
sebastien-rosset Sep 27, 2017
95d62cb
Print log statement when skipping Wipe()
sebastien-rosset Sep 27, 2017
c1b4e88
Add more debugging
sebastien-rosset Dec 8, 2017
cf48096
Add more debugging
sebastien-rosset Dec 8, 2017
3fcf468
Improve logging for unit tests
sebastien-rosset May 11, 2019
fd583cf
Add option to attach UT container to a specific docker network
sebastien-rosset May 11, 2019
b58a6c5
Add option to attach UT container to a specific docker network. Run g…
sebastien-rosset May 11, 2019
bb13221
Add option to attach UT container to a specific docker network. Disco…
sebastien-rosset May 12, 2019
c83ef01
Add option to attach UT container to a specific docker network. Add c…
sebastien-rosset May 12, 2019
b8a31fb
Add option to attach UT container to a specific docker network.
sebastien-rosset May 12, 2019
498ec52
Add option to attach UT container to a specific docker network.
sebastien-rosset May 12, 2019
0f9e67f
Add option to attach UT container to a specific docker network.
sebastien-rosset May 13, 2019
e1f5322
Add knob to expose container port to host
sebastien-rosset Jun 3, 2019
f191882
Add knob to expose container port to host
sebastien-rosset Jun 3, 2019
90de89a
Add knob to expose container port to host
sebastien-rosset Jun 3, 2019
3151693
Add knob to expose container port to host
sebastien-rosset Jun 4, 2019
8057a00
Add knob to expose container port to host
sebastien-rosset Jun 4, 2019
3a88deb
bson: add WithContext versions of API functions
Jul 3, 2019
e7448e4
Added "PartialFilterExpression" support to Indexes. If specified, the…
pfeairheller Sep 27, 2016
c056e84
bson: remove Debug()
Jul 9, 2019
919881f
Merge pull request #1 from CiscoM31/v2.1_with_context
fraley Jul 10, 2019
5c2d368
removes the deprecated MMAPv1 storage engine and the MMAPv1-specific …
Dec 5, 2019
a4fc895
Adding support for starting mongo test server in replicaset formation
Dec 6, 2019
5216163
Adding support for starting mongo test server in replicaset formation
Dec 9, 2019
aee4b9c
Merge pull request #2 from CiscoM31/v2.1.panair-rmmap
parvathi-nair Dec 10, 2019
76f864a
Add method to set container name
sebastien-rosset Mar 23, 2020
ec2e737
use log package to log records
sebastien-rosset Jun 29, 2020
4e59dc0
use log package to log records
sebastien-rosset Jun 29, 2020
f43e66b
use log package to log records
sebastien-rosset Jun 29, 2020
16644d4
Adding Support for Collation in Query
Jul 29, 2020
675844a
Merge pull request #3 from CiscoM31/collate
parvathi-nair Aug 4, 2020
293db6d
add check to determine if image exists locally before doing docker pull
sebastien-rosset Nov 25, 2020
4efb54b
add check to determine if image exists locally before doing docker pull
sebastien-rosset Nov 25, 2020
a696e6a
add check to determine if image exists locally before doing docker pull
sebastien-rosset Nov 25, 2020
8850ab9
add check to determine if image exists locally before doing docker pull
sebastien-rosset Nov 25, 2020
7b8cdc5
Merge pull request #4 from CiscoM31/check-if-docker-image-exists
sebastien-rosset Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions bson/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ package bson

import (
"bytes"
"context"
"crypto/md5"
"crypto/rand"
"encoding/binary"
Expand Down Expand Up @@ -64,6 +65,10 @@ type Getter interface {
GetBSON() (interface{}, error)
}

type GetterCtx interface {
GetBSONWithContext(context.Context) (interface{}, error)
}

// A value implementing the bson.Setter interface will receive the BSON
// value via the SetBSON method during unmarshaling, and the object
// itself will not be changed as usual.
Expand Down Expand Up @@ -95,6 +100,10 @@ type Setter interface {
SetBSON(raw Raw) error
}

type SetterCtx interface {
SetBSONWithContext(ctx context.Context, raw Raw) error
}

// SetZero may be returned from a SetBSON method to have the value set to
// its respective zero value. When used in pointer values, this will set the
// field to nil rather than to the pre-allocated value.
Expand Down Expand Up @@ -279,7 +288,7 @@ var nullBytes = []byte("null")
func (id *ObjectId) UnmarshalJSON(data []byte) error {
if len(data) > 0 && (data[0] == '{' || data[0] == 'O') {
var v struct {
Id json.RawMessage `json:"$oid"`
Id json.RawMessage `json:"$oid"`
Func struct {
Id json.RawMessage
} `json:"$oidFunc"`
Expand Down Expand Up @@ -505,13 +514,17 @@ func handleErr(err *error) {
// F int64 "myf,omitempty,minsize"
// }
//
func Marshal(in interface{}) (out []byte, err error) {
func MarshalWithContext(ctx context.Context, in interface{}) (out []byte, err error) {
defer handleErr(&err)
e := &encoder{make([]byte, 0, initialBufferSize)}
e.addDoc(reflect.ValueOf(in))
e.addDoc(ctx, reflect.ValueOf(in))
return e.out, nil
}

func Marshal(in interface{}) (out []byte, err error) {
return MarshalWithContext(context.TODO(), in)
}

// Unmarshal deserializes data from in into the out value. The out value
// must be a map, a pointer to a struct, or a pointer to a bson.D value.
// In the case of struct values, only exported fields will be deserialized.
Expand Down Expand Up @@ -547,7 +560,7 @@ func Marshal(in interface{}) (out []byte, err error) {
// silently skipped.
//
// Pointer values are initialized when necessary.
func Unmarshal(in []byte, out interface{}) (err error) {
func UnmarshalWithContext(ctx context.Context, in []byte, out interface{}) (err error) {
if raw, ok := out.(*Raw); ok {
raw.Kind = 3
raw.Data = in
Expand All @@ -560,7 +573,7 @@ func Unmarshal(in []byte, out interface{}) (err error) {
fallthrough
case reflect.Map:
d := newDecoder(in)
d.readDocTo(v)
d.readDocTo(ctx, v)
case reflect.Struct:
return errors.New("Unmarshal can't deal with struct values. Use a pointer.")
default:
Expand All @@ -569,12 +582,16 @@ func Unmarshal(in []byte, out interface{}) (err error) {
return nil
}

func Unmarshal(in []byte, out interface{}) (err error) {
return UnmarshalWithContext(context.TODO(), in, out)
}

// Unmarshal deserializes raw into the out value. If the out value type
// is not compatible with raw, a *bson.TypeError is returned.
//
// See the Unmarshal function documentation for more details on the
// unmarshalling process.
func (raw Raw) Unmarshal(out interface{}) (err error) {
func (raw Raw) UnmarshalWithContext(ctx context.Context, out interface{}) (err error) {
defer handleErr(&err)
v := reflect.ValueOf(out)
switch v.Kind() {
Expand All @@ -583,7 +600,7 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
fallthrough
case reflect.Map:
d := newDecoder(raw.Data)
good := d.readElemTo(v, raw.Kind)
good := d.readElemTo(ctx, v, raw.Kind)
if !good {
return &TypeError{v.Type(), raw.Kind}
}
Expand All @@ -595,6 +612,10 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
return nil
}

func (raw Raw) Unmarshal(out interface{}) (err error) {
return raw.UnmarshalWithContext(context.TODO(), out)
}

type TypeError struct {
Type reflect.Type
Kind byte
Expand Down
89 changes: 89 additions & 0 deletions bson/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// BSON library for Go
//
// Copyright (c) 2010-2012 - Gustavo Niemeyer <gustavo@niemeyer.net>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// gobson - BSON library for Go.
//

package bson

import (
"context"
"fmt"
"reflect"
"strings"
)

type bsonOptions struct {
// skipCustom is used by
// - decode.go to skip looking for a custom SetBSON() or SetBSONWithContext()
// - encode.go to skip looking for a custom GetBSON() or GetBSONWithContext()
// for any type with the base type name specified by 'skipCustom'.
// This is useful to avoid infinite loop caused by:
// - calling Unmarshal from custom SetBSON function (decode.go)
// - encode.go calling custom GetBSON after just calling custom GetBSON for a given type
skipCustom string
}

type key int

var bsonKey key = 0

// Returns the topmost bsonOptions value stored in ctx, if any.
func fromContext(ctx context.Context) (*bsonOptions, bool) {
if ctx == nil {
return nil, false
}
opts, ok := ctx.Value(bsonKey).(*bsonOptions)
return opts, ok
}

// Returns the base type name (type name without a prefix that contains any combination of * or []).
func baseTypeName(typ reflect.Type) string {
return strings.Trim(fmt.Sprintf("%v", typ), "*[]")
}

// Creates a new context with a value for skipCustom based on base type name of valu.
func NewContextWithSkipCustom(ctx context.Context, valu interface{}) context.Context {
if ctx == nil {
ctx = context.Background()
}
return context.WithValue(ctx, bsonKey, &bsonOptions{skipCustom: baseTypeName(reflect.TypeOf(valu))})
}

// IsSkipCustom is useful to avoid infinite loop caused by:
// - calling Unmarshal from custom SetBSON function (decode.go)
// - encode.go calling custom GetBSON after just calling custom GetBSON for a given type
//
// Returns true if base type name of typ is the same as skipCustom.
//
// This method is used to skip all custom SetBSON/GetBSON functions of all types with the same base type.
// Note: if goal is to skip the custom functions of certain variations of a base type,
// skipCustom will not work (it will skip all variants).
func IsSkipCustom(ctx context.Context, typ reflect.Type) bool {
if opts, _ := fromContext(ctx); opts != nil {
return opts.skipCustom == baseTypeName(typ)
}
return false
}
Loading