Skip to content

Commit

Permalink
Merge branch 'release/v0.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddspog committed Apr 16, 2018
2 parents 43d6241 + e4c137b commit 1ad521b
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 155 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mongodb://localhost:27017/test

## Mocking

You can mock some functionalities of this package, by mocking the mgo
You can mock some functions of this package, by mocking the mgo
called functions mgo.ParseURL and mgo.Dial. Use the MockMongoSetup
presented on this package (only in test environment), like:

Expand All @@ -69,7 +69,7 @@ if err := mongo.Connect(); err != nil {
## Testing

This package contains a nice coverage with the unit tests, within the
objetives of the project.
objectives of the project.

The elements, embedded and mocks sub-packages have low coverage because
they fulfill a need to mock mgo elements. These packages only embedded
Expand Down
50 changes: 25 additions & 25 deletions acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
_ = Connect()
defer Disconnect()

conn := NewDBSocket()
conn := newDBSocket()
defer conn.Close()
db := conn.DB()

p := NewProductHandle()
p := newProductHandle()
p.Link(db)

when("using p.RemoveAll()", func(it bdd.It) {
Expand All @@ -51,15 +51,15 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it("should have p.Count() return 0", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
n, errCount := p.Count()

assert.NoError(errCount)
assert.Equal(0, n)
})

it("should have p.FindAll() return nothing", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
products, errFindAll := p.FindAll()

assert.NoError(errFindAll)
Expand All @@ -70,19 +70,19 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
var newId bson.ObjectId

when(fmt.Sprintf("using p.Insert() to add documents with ids: '%[1]s', '%[2]s', '%[3]s', and a new one", testid01, testid02, testid03), func(it bdd.It) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid01)
errInsertDoc01 := p.Insert()

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid02)
errInsertDoc02 := p.Insert()

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid03)
errInsertDoc03 := p.Insert()

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
errInsertDoc04 := p.Insert()
newId = p.DocumentV.ID()

Expand All @@ -94,36 +94,36 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it("should have p.Count() return 4", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
n, errCount := p.Count()

assert.NoError(errCount)
assert.Equal(4, n)
})

it("should have p.Find() return all documents", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid01)
product01, errFindDoc01 := p.Find()

assert.NoError(errFindDoc01)
assert.Equal(testid01, product01.ID().Hex())

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid02)
product02, errFindDoc02 := p.Find()

assert.NoError(errFindDoc02)
assert.Equal(testid02, product02.ID().Hex())

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = bson.ObjectIdHex(testid03)
product03, errFindDoc03 := p.Find()

assert.NoError(errFindDoc03)
assert.Equal(testid03, product03.ID().Hex())

p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = newId
newProduct, errFindNewDoc := p.Find()

Expand All @@ -135,7 +135,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
now := model.NowInMilli()

when(fmt.Sprintf("using p.Update() to change created_on doc with id '%[1]s' to '%[2]v'", newId.Hex(), now), func(it bdd.It) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.CreatedOnV = now
errUpdate := p.Update(newId)

Expand All @@ -144,7 +144,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it(fmt.Sprintf("should have p.Find() with id '%[1]s' return with new value", newId.Hex()), func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = newId
product, errFind := p.Find()

Expand All @@ -155,7 +155,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it("should have p.Count() return 4", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
n, errCount := p.Count()

assert.NoError(errCount)
Expand All @@ -164,7 +164,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

when(fmt.Sprintf("using p.Remove() to remove doc with id '%[1]s'", newId.Hex()), func(it bdd.It) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = newId
errRemove := p.Remove()

Expand All @@ -173,7 +173,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it(fmt.Sprintf("should have p.Find() with id '%[1]s' return nothing", newId.Hex()), func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
p.DocumentV.IDV = newId
product, errFind := p.Find()

Expand All @@ -183,7 +183,7 @@ func Test_Manipulate_data_on_MongoDB(t *testing.T) {
})

it("should have p.Count() return 3", func(assert bdd.Assert) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
n, errCount := p.Count()

assert.NoError(errCount)
Expand All @@ -210,7 +210,7 @@ func Test_Real_connection_to_MongoDB(t *testing.T) {
assert.NoError(err)
})

conn := NewDBSocket()
conn := newDBSocket()
defer conn.Close()

db := conn.DB()
Expand All @@ -219,7 +219,7 @@ func Test_Real_connection_to_MongoDB(t *testing.T) {
assert.NotNil(db)
})

p, err := NewProductHandle().Link(db)
p, err := newProductHandle().Link(db)

it("should link correctly with products collection", func(assert bdd.Assert) {
assert.NoError(err)
Expand All @@ -238,7 +238,7 @@ func Test_Real_connection_to_MongoDB(t *testing.T) {
// Feature Read data on MongoDB
// - As a developer,
// - I want to be able to connect and retrieve data from MongoDB,
// - So I can use these functionalities on real applications.
// - So I can use these functions on real applications.
func Test_Read_data_on_MongoDB(t *testing.T) {
given, like, s := bdd.Sentences()

Expand All @@ -247,11 +247,11 @@ func Test_Read_data_on_MongoDB(t *testing.T) {
_ = Connect()
defer Disconnect()

conn := NewDBSocket()
conn := newDBSocket()
defer conn.Close()
db := conn.DB()

p := NewProductHandle()
p := newProductHandle()
p.Link(db)

when("using p.Find() with '%[1]v' as document id'", func(it bdd.It, args ...interface{}) {
Expand All @@ -270,7 +270,7 @@ func Test_Read_data_on_MongoDB(t *testing.T) {
))

when("using p.FindAll() with a empty Document", func(it bdd.It) {
p.DocumentV = NewProduct()
p.DocumentV = newProduct()
products, errFindAll := p.FindAll()

it("should run without errors", func(assert bdd.Assert) {
Expand Down
4 changes: 2 additions & 2 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func Connect() (err error) {
var m *elements.DialInfo
m, err = parseURL(u)
if err != nil {
err = fmt.Errorf("Problem parsing Mongo URI. uri=%[1]s err='%[2]v'", u, err.Error())
err = fmt.Errorf("problem parsing Mongo URI uri=%[1]s err='%[2]v'", u, err.Error())
return
}
var s elements.Sessioner
s, err = dial(u)
if err != nil {
err = fmt.Errorf("Problem dialing Mongo URI. uri=%[1]s err='%[2]v'", u, err.Error())
err = fmt.Errorf("problem dialing Mongo URI uri=%[1]s err='%[2]v'", u, err.Error())
return
}

Expand Down
6 changes: 3 additions & 3 deletions connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_Connection_with_MongoDB(t *testing.T) {

makeMGO, _ := mocks.NewMockMGOSetup(t)
makeMongo, _ := NewMockMongoSetup(t)
defer Finish(makeMGO, makeMongo)
defer finish(makeMGO, makeMongo)

given, _, _ := bdd.Sentences()

Expand All @@ -45,7 +45,7 @@ func Test_Connection_with_MongoDB(t *testing.T) {
var errCount, errLink error

ConsumeDatabaseOnSession(func(db elements.Databaser) {
p := NewProductHandle()
p := newProductHandle()
_, errLink = p.Link(db)
n, errCount = p.Count()
})
Expand Down Expand Up @@ -73,7 +73,7 @@ func Test_Connect_only_with_valid_URLs(t *testing.T) {

makeMGO, _ := mocks.NewMockMGOSetup(t)
makeMongo, _ := NewMockMongoSetup(t)
defer Finish(makeMGO, makeMongo)
defer finish(makeMGO, makeMongo)

given, _, _ := bdd.Sentences()

Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ variable, but when it's not defined, it uses a default URL:
Mocking
You can mock some functionalities of this package, by mocking the mgo
You can mock some functions of this package, by mocking the mgo
called functions mgo.ParseURL and mgo.Dial. Use the MockMongoSetup
presented on this package (only in test environment), like:
Expand Down
Loading

0 comments on commit 1ad521b

Please sign in to comment.