Description
package main_test
|
|
|
import (
|
"encoding/json"
|
"log"
|
"testing"
|
|
|
"github.com/mongodb/mongo-go-driver/bson"
|
"github.com/stretchr/testify/assert"
|
bsonmgo "gopkg.in/mgo.v2/bson"
|
)
|
|
|
// SomeInterface -
|
type SomeInterface interface {
|
}
|
|
|
// SomeStruct -
|
type SomeStruct struct {
|
SomeInterface
|
}
|
|
|
// SomeParentStruct -
|
type SomeParentStruct struct {
|
Name string `bson:"name"`
|
Child SomeInterface `bson:"interface"`
|
}
|
|
|
// Validate that we can JSON Marshal the structure
|
func TestJSON(t *testing.T) {
|
st := SomeStruct{}
|
structExample := SomeParentStruct{
|
Child: st,
|
}
|
doc, err := json.Marshal(structExample)
|
assert.Equal(t, err, nil, "JSON")
|
log.Printf("%s", doc)
|
}
|
|
|
// Validate that we can BSON Marshal the structure with MGO lib
|
func TestMgoBSON(t *testing.T) {
|
st := SomeStruct{}
|
structExample := SomeParentStruct{
|
Child: st,
|
}
|
doc, err := bsonmgo.Marshal(structExample)
|
assert.Equal(t, err, nil, "JSON")
|
log.Printf("%s", doc)
|
}
|
|
|
// Validate that we cannot BSON Marshal the structure with official mongo lib
|
func TestMongoBSON(t *testing.T) {
|
st := SomeStruct{}
|
structExample := SomeParentStruct{
|
Child: st,
|
}
|
doc, err := bson.Marshal(structExample)
|
assert.Equal(t, err, nil, "JSON")
|
log.Printf("%s", doc)
|
}
|
|
Attachments
Issue Links
- depends on
-
GODRIVER-317 Handle nil properties of a struct in the BSON encoder
-
- Closed
-
- duplicates
-
GODRIVER-317 Handle nil properties of a struct in the BSON encoder
-
- Closed
-