replace third_party with go get and fix accounts / settings tests

This commit is contained in:
Willy Kloucek
2021-10-14 15:56:19 +02:00
parent 42b60fddb6
commit fcb1c4225b
21 changed files with 140 additions and 1926 deletions
+7 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/gofrs/uuid"
"github.com/owncloud/ocis/settings/pkg/proto/v0"
"github.com/owncloud/ocis/settings/pkg/store/errortypes"
)
var m = &sync.RWMutex{}
@@ -110,7 +111,12 @@ func (s Store) WriteBundle(record *proto.Bundle) (*proto.Bundle, error) {
func (s Store) AddSettingToBundle(bundleID string, setting *proto.Setting) (*proto.Setting, error) {
bundle, err := s.ReadBundle(bundleID)
if err != nil {
return nil, err
if _, notFound := err.(errortypes.BundleNotFound); !notFound {
return nil, err
}
bundle = new(proto.Bundle)
bundle.Id = bundleID
bundle.Type = proto.Bundle_TYPE_DEFAULT
}
if setting.Id == "" {
setting.Id = uuid.Must(uuid.NewV4()).String()
+14 -2
View File
@@ -4,12 +4,18 @@ import (
"io/ioutil"
"os"
"github.com/owncloud/ocis/settings/pkg/store/errortypes"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
// Unmarshal file into record
func (s Store) parseRecordFromFile(record proto.Message, filePath string) error {
_, err := os.Stat(filePath)
if err != nil {
return errortypes.BundleNotFound(err.Error())
}
file, err := os.Open(filePath)
if err != nil {
return err
@@ -21,6 +27,10 @@ func (s Store) parseRecordFromFile(record proto.Message, filePath string) error
return err
}
if len(b) == 0 {
return errortypes.BundleNotFound(filePath)
}
if err := protojson.Unmarshal(b, record); err != nil {
return err
}
@@ -35,10 +45,12 @@ func (s Store) writeRecordToFile(record proto.Message, filePath string) error {
}
defer file.Close()
if v, err := protojson.Marshal(record); err != nil {
file.Write(v)
v, err := protojson.Marshal(record)
if err != nil {
return err
}
file.Write(v)
return nil
}