defer close rows, change paste not found behavior
This commit is contained in:
parent
c526fa7862
commit
eaecb1b38b
|
@ -95,13 +95,18 @@ func (s *StorageSqlite) Get(id string) (*storage.Paste, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err := stmt.Query(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var p storage.Paste
|
||||
|
||||
if !rows.Next() {
|
||||
return nil, nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var plain = 0
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ func testGetSave(s *sqlite.StorageSqlite, t * testing.T) {
|
|||
t.Fatalf("Purged %v rows, expect 1 row", affected)
|
||||
}
|
||||
|
||||
var p_a, _ *storage.Paste
|
||||
var p_a, p_b, _ *storage.Paste
|
||||
|
||||
if p_a, err = s.Get(id_a); err != nil {
|
||||
t.Fatalf("Fatal on Get a: %v", err)
|
||||
|
@ -71,8 +71,7 @@ func testGetSave(s *sqlite.StorageSqlite, t * testing.T) {
|
|||
t.Fatal("Content not match")
|
||||
}
|
||||
}
|
||||
if _, err = s.Get(id_b); err == nil {
|
||||
if p_b, err = s.Get(id_b); err == nil && p_b != nil {
|
||||
t.Fatalf("Fatal on Get b, it shoud have been purged")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package storage
|
||||
|
||||
type Storage interface {
|
||||
Save(Paste) (string, error)
|
||||
Save(*Paste) (string, error)
|
||||
Get(string) (*Paste, error)
|
||||
Purge() (int64, error)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue