-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug that multi db use the dafult database, and add related test case
- Loading branch information
Showing
2 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package mgodb | ||
|
||
import ( | ||
"labix.org/v2/mgo" | ||
"labix.org/v2/mgo/bson" | ||
"testing" | ||
) | ||
|
||
const ( | ||
ALLUSERS = "allusers" | ||
DB1 = "mogdb_test_1" | ||
DB2 = "mogdb_test_2" | ||
) | ||
|
||
func TestSave(t *testing.T) { | ||
db := NewDatabase("localhost", DB1) | ||
|
||
db.Save(ALLUSERS, &User{Email: "sunfmin@gmail.com", Name: "Felix Sun"}) | ||
|
||
var found *User | ||
db.CollectionDo(ALLUSERS, func(uc *mgo.Collection) { | ||
uc.Find(bson.M{"email": "sunfmin@gmail.com"}).One(&found) | ||
}) | ||
if found == nil { | ||
t.Error("Can not find user after saved") | ||
} | ||
|
||
db = NewDatabase("localhost", DB2) | ||
|
||
db.Save(ALLUSERS, &User{Email: "sunfmin@gmail.com", Name: "Felix Sun"}) | ||
|
||
var u2 *User | ||
db.CollectionDo(ALLUSERS, func(uc *mgo.Collection) { | ||
uc.Find(bson.M{"email": "sunfmin@gmail.com"}).One(&u2) | ||
}) | ||
if u2 == nil { | ||
t.Error("Can not find user after saved") | ||
} | ||
|
||
} |