* Removed a concurrent write condition that was happening while fetching BD * Updated the local test database to match bedetheque.com state * Note field being highly dynamic removed test from it.
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
. "gopkg.in/check.v1"
|
|
)
|
|
|
|
type AlbumDatabaseSuite struct {
|
|
db *AlbumDatabase
|
|
}
|
|
|
|
var _ = Suite(&AlbumDatabaseSuite{})
|
|
|
|
func (s *AlbumDatabaseSuite) SetUpSuite(c *C) {
|
|
s.db = OpenAlbumDatabase(filepath.Join(c.MkDir(), "satdb.bar.satellite/db"))
|
|
for _, a := range albumsDataTest {
|
|
//we need to copy the value to avoid aliasing
|
|
aCopied := a
|
|
c.Assert(s.db.AddOrUpdate(&aCopied), IsNil)
|
|
}
|
|
}
|
|
|
|
func (s *AlbumDatabaseSuite) TestCanDelete(c *C) {
|
|
defer func() {
|
|
//we can always add it twice
|
|
c.Assert(s.db.AddOrUpdate(&(albumsDataTest[0])), IsNil)
|
|
}()
|
|
|
|
c.Assert(s.db.Delete(albumsDataTest[0].ID), IsNil)
|
|
}
|
|
|
|
func (s *AlbumDatabaseSuite) TestCanGet(c *C) {
|
|
for _, a := range albumsDataTest {
|
|
fromDb, err := s.db.Get(a.ID)
|
|
if c.Check(err, IsNil) == true {
|
|
c.Check(*fromDb, DeepEquals, a)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *AlbumDatabaseSuite) TestCanSort(c *C) {
|
|
start := time.Now()
|
|
|
|
sorted, err := s.db.ByPurchaseDate()
|
|
|
|
log.Printf("sorting took %s", time.Since(start))
|
|
|
|
c.Assert(err, IsNil)
|
|
c.Assert(len(sorted) > 0, Equals, true)
|
|
last := time.Now()
|
|
for _, a := range sorted {
|
|
al, err := s.db.get(fmt.Sprintf("%d", a))
|
|
if c.Check(err, IsNil) == false {
|
|
continue
|
|
}
|
|
c.Check(last.After(al.PurchaseDate), Equals, true)
|
|
}
|
|
}
|