diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index 12f7a55321..47466ac4cd 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -122,23 +122,16 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) { ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t) - ureq, err := http.NewRequest("DELETE", fmt.Sprintf("http://localhost:9187/data/accounts/%s", id), nil) + _, err = r.storageClient.Delete(ctx, &provider.DeleteRequest{ + Ref: &provider.Reference{ + Spec: &provider.Reference_Path{Path: fmt.Sprintf("/meta/accounts/%s", id)}, + }, + }) + if err != nil { return err } - ureq.Header.Add("x-access-token", t) - cl := http.Client{ - Transport: http.DefaultTransport, - } - - resp, err := cl.Do(ureq) - if err != nil { - return err - } - - defer resp.Body.Close() - return nil } @@ -149,7 +142,6 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) { } ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t) - ureq, err := http.NewRequest("DELETE", fmt.Sprintf("http://localhost:9187/data/groups/%s", id), nil) if err != nil { return err diff --git a/accounts/pkg/storage/cs3_test.go b/accounts/pkg/storage/cs3_test.go index 1a55c80996..a99efecbd4 100644 --- a/accounts/pkg/storage/cs3_test.go +++ b/accounts/pkg/storage/cs3_test.go @@ -1,7 +1,13 @@ package storage -/* -func TestFoo(t *testing.T) { +import ( + "context" + "github.com/owncloud/ocis/accounts/pkg/proto/v0" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestCS3Repo_WriteAccount(t *testing.T) { r, err := NewCS3Repo("fooo") assert.NoError(t, err) @@ -15,4 +21,39 @@ func TestFoo(t *testing.T) { assert.NoError(t, err) } -*/ +func TestCS3Repo_LoadAccount(t *testing.T) { + r, err := NewCS3Repo("fooo") + assert.NoError(t, err) + + err = r.WriteAccount(context.Background(), &proto.Account{ + Id: "fefef-egegweg-gegeg", + AccountEnabled: true, + DisplayName: "Mike Jones", + Mail: "mike@example.com", + }) + + acc := &proto.Account{} + err = r.LoadAccount(context.Background(), "fefef-egegweg-gegeg", acc) + + assert.NoError(t, err) + assert.Equal(t, "fefef-egegweg-gegeg", acc.Id) + assert.Equal(t, "Mike Jones", acc.DisplayName) + assert.Equal(t, "mike@example.com", acc.Mail) +} + +func TestCS3Repo_DeleteAccount(t *testing.T) { + r, err := NewCS3Repo("fooo") + assert.NoError(t, err) + + err = r.WriteAccount(context.Background(), &proto.Account{ + Id: "delete-me-id", + AccountEnabled: true, + DisplayName: "Mike Jones", + Mail: "mike@example.com", + }) + + err = r.DeleteAccount(context.Background(), "delete-me-id") + + assert.NoError(t, err) + +}