add some basic sdk tests, fix saving hints (normalize urls), checkduplicates arg order, kvdb stuff and other things.

This commit is contained in:
fiatjaf
2025-01-16 17:38:03 -03:00
parent 46569b6ef4
commit febf022124
15 changed files with 121 additions and 58 deletions

View File

@@ -76,7 +76,9 @@ func (s *Store) Update(key []byte, f func([]byte) ([]byte, error)) error {
}
newVal, err := f(val)
if err != nil {
if err == kvstore.NoOp {
return nil
} else if err != nil {
return err
}

View File

@@ -104,7 +104,9 @@ func (s *Store) Update(key []byte, f func([]byte) ([]byte, error)) error {
}
newVal, err := f(val)
if err != nil {
if err == kvstore.NoOp {
return nil
} else if err != nil {
return err
}

View File

@@ -22,7 +22,7 @@ func NewStore() *Store {
func (s *Store) Get(key []byte) ([]byte, error) {
s.RLock()
defer s.RUnlock()
if val, ok := s.data[string(key)]; ok {
// Return a copy to prevent modification of stored data
cp := make([]byte, len(val))
@@ -35,7 +35,7 @@ func (s *Store) Get(key []byte) ([]byte, error) {
func (s *Store) Set(key []byte, value []byte) error {
s.Lock()
defer s.Unlock()
// Store a copy to prevent modification of stored data
cp := make([]byte, len(value))
copy(cp, value)
@@ -69,7 +69,9 @@ func (s *Store) Update(key []byte, f func([]byte) ([]byte, error)) error {
}
newVal, err := f(val)
if err != nil {
if err == kvstore.NoOp {
return nil
} else if err != nil {
return err
}

5
sdk/kvstore/noop.go Normal file
View File

@@ -0,0 +1,5 @@
package kvstore
import "fmt"
var NoOp = fmt.Errorf("noop")