good morning!!!!

Skip to content
Snippets Groups Projects
Commit f66d91d4 authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Writing Connect and Find tests.

parent 67773dbb
Branches
No related tags found
No related merge requests found
......@@ -366,7 +366,7 @@ func (c *MongoDBCollection) FindAll(terms ...interface{}) []Item {
for key, val := range result[i].(bson.M) {
item[key] = val
}
items = append(items, item)
items[i] = item
}
return items
......
......@@ -2,11 +2,24 @@ package db
import (
//. "github.com/xiam/gosexy"
"fmt"
"testing"
)
func TestAll(t *testing.T) {
func TestConnect(t *testing.T) {
db := NewMongoDB(&DataSource{ Host: "dns.fail", Database: "test" })
err := db.Connect()
if err != nil {
t.Logf("Got %t, this was intended.", err)
return
}
t.Error("Are you serious?")
}
func TestAppend(t *testing.T) {
db := NewMongoDB(&DataSource{ Host: "localhost", Database: "test" })
......@@ -16,35 +29,19 @@ func TestAll(t *testing.T) {
panic(err)
}
// Choose database
/* Choose database */
db.Use("test")
// Choose collection
/* Choose collection */
col := db.Collection("people")
all := col.FindAll()
/* Trying to get 10 records */
all := col.FindAll(Limit(10))
for i := 0; i < len(all); i++ {
t.Logf("item[%t]\n", i)
for key, val := range all[i] {
fmt.Printf("key(%v) = (%v)\n", key, val)
t.Logf("\t%t: %t\n", key, val)
}
}
/*
// Testing insert
col.Append(Tuple { "Name": "Tucket11", "LastName": "Nancy" })
found := col.Find(
Where { "Name": "Tucket3" },
Where { "LastName $ne": "Barr" },
)
fmt.Printf("Find: %v\n", found)
col.Update(Where {"Name": "Tucket" }, Set { "FooSet": "Bar", "Name": "Tucket3" })
col.UpdateAll(Where {"Name": "Tucket5" }, Upsert { "Heh": "Bar" })
col.Update(Where {"Name": "Tucket3" }, Modify { "$unset": "FooSet" })
col.Remove(Where { "Name": "Tucket" })
col.RemoveAll(Where { "Name": "Tucket" })
*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment