make values unit tests green

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2022-02-25 15:58:48 +01:00
parent 45c85f4237
commit 721026654d
2 changed files with 22 additions and 7 deletions
+17 -2
View File
@@ -2,7 +2,9 @@
package store
import (
"encoding/json"
"errors"
"fmt"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
)
@@ -17,7 +19,12 @@ func (s Store) ListValues(bundleID, accountUUID string) ([]*settingsmsg.Value, e
// ReadValue tries to find a value by the given valueId within the dataPath
func (s Store) ReadValue(valueID string) (*settingsmsg.Value, error) {
return nil, errors.New("not implemented")
b, err := s.mdc.SimpleDownload(nil, valuePath(valueID))
if err != nil {
return nil, err
}
val := &settingsmsg.Value{}
return val, json.Unmarshal(b, val)
}
// ReadValueByUniqueIdentifiers tries to find a value given a set of unique identifiers
@@ -27,5 +34,13 @@ func (s Store) ReadValueByUniqueIdentifiers(accountUUID, settingID string) (*set
// WriteValue writes the given value into a file within the dataPath
func (s Store) WriteValue(value *settingsmsg.Value) (*settingsmsg.Value, error) {
return nil, errors.New("not implemented")
b, err := json.Marshal(value)
if err != nil {
return nil, err
}
return value, s.mdc.SimpleUpload(nil, valuePath(value.Id), b)
}
func valuePath(id string) string {
return fmt.Sprintf("%s/%s", "settings/values", id)
}
+5 -5
View File
@@ -5,7 +5,7 @@ import (
olog "github.com/owncloud/ocis/ocis-pkg/log"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var valueScenarios = []struct {
@@ -60,12 +60,12 @@ func TestValues(t *testing.T) {
t.Run(valueScenarios[index].name, func(t *testing.T) {
value := valueScenarios[index].value
v, err := s.WriteValue(value)
assert.NoError(t, err)
assert.Equal(t, value, v)
require.NoError(t, err)
require.Equal(t, value, v)
v, err = s.ReadValue(value.Id)
assert.NoError(t, err)
assert.Equal(t, value, v)
require.NoError(t, err)
require.Equal(t, value, v)
})
}