mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
feat(be): implement options for boltdb
This commit is contained in:
parent
710c7df275
commit
522513b375
@ -12,7 +12,7 @@ func (d *BoltDb) SetOption(key string, value string) error {
|
||||
Value: value,
|
||||
}
|
||||
|
||||
_, err := d.GetOption(key)
|
||||
_, err := d.getOption(key)
|
||||
|
||||
if errors.Is(err, db.ErrNotFound) {
|
||||
_, err = d.createObject(-1, db.OptionProps, opt)
|
||||
@ -24,9 +24,21 @@ func (d *BoltDb) SetOption(key string, value string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *BoltDb) GetOption(key string) (value string, err error) {
|
||||
func (d *BoltDb) getOption(key string) (value string, err error) {
|
||||
var option db.Option
|
||||
err = d.getObject(-1, db.OptionProps, strObjectID(key), &option)
|
||||
value = option.Value
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) GetOption(key string) (value string, err error) {
|
||||
var option db.Option
|
||||
err = d.getObject(-1, db.OptionProps, strObjectID(key), &option)
|
||||
value = option.Value
|
||||
|
||||
if errors.Is(err, db.ErrNotFound) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
package bolt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetOption(t *testing.T) {
|
||||
store := CreateTestStore()
|
||||
|
||||
_, err := store.GetOption("unknown_option")
|
||||
val, err := store.GetOption("unknown_option")
|
||||
|
||||
if !errors.Is(err, db.ErrNotFound) {
|
||||
t.Fatal("Result must be nil for non-existent option")
|
||||
if err != nil && val != "" {
|
||||
t.Fatal("Result must be empty string for non-existent option")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user