From fe87a78bb111ce6f15c881676901d256fd589532 Mon Sep 17 00:00:00 2001 From: Rebecca Vest Date: Fri, 10 Nov 2017 15:07:01 -0700 Subject: [PATCH] Added revoke_shared_link; updated tests --- sharing.go | 16 ++++++++++++ sharing_test.go | 67 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/sharing.go b/sharing.go index ea64a98..ce1824c 100644 --- a/sharing.go +++ b/sharing.go @@ -91,6 +91,22 @@ func (c *Sharing) ListSharedLinks(in *ListShareLinksInput) (out *ListShareLinksO return } +type RevokeSharedLinkInput struct { + Url string `json:"url"` +} + + +func (c *Sharing) RevokeSharedLink(in *RevokeSharedLinkInput) (err error) { + + endpoint := "/sharing/revoke_shared_link" + _, err := c.call(endpoint, in) + if err != nil { + return + } + + return +} + // ListSharedFolderInput request input. type ListSharedFolderInput struct { Limit uint64 `json:"limit"` diff --git a/sharing_test.go b/sharing_test.go index 9aaad6b..45bb966 100644 --- a/sharing_test.go +++ b/sharing_test.go @@ -8,12 +8,33 @@ import ( func TestSharing_CreateSharedLink(t *testing.T) { c := client() - out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{ - Path: "/hello.txt", - }) + //list shares + links, _ := c.Sharing.ListSharedLinks(&ListShareLinksInput { + Path: "/hello.txt", + }) - assert.NoError(t, err, "error sharing file") - assert.Equal(t, "/hello.txt", out.Path) + var sharedLink string + if len(links.Links) == 0 { + out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{ + Path: "/hello.txt", + }) + + assert.NoError(t, err, "error sharing file") + assert.Contains(t, out.URL, "/hello.txt") + } else { + sharedLink = links.Links[0].URL + + err := c.Sharing.RevokeSharedLink(&RevokeSharedLinkInput{ + Url: sharedLink, + }) + + out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{ + Path: "/hello.txt", + }) + + assert.NoError(t, err, "error sharing file") + assert.Contains(t, out.URL, "/hello.txt") + } } func TestSharing_ListSharedFolder(t *testing.T) { @@ -34,3 +55,39 @@ func TestSharing_ListSharedFolder(t *testing.T) { assert.NotEmpty(t, out.Entries, "output should be non-empty") } } + +func TestSharing_ListSharedLinks(t *testing.T) { + c := client() + out, err := c.Sharing.ListSharedLinks(&ListShareLinksInput{ + Path: "/hello.txt", + }) + + assert.NoError(t, err, "listing shared folders") + assert.NotEmpty(t, out.Links, "output should be non-empty") +} + +func TestSharing_RevokeSharedLink(t *testing.T) { + c := client() + + links, err := c.Sharing.ListSharedLinks(&ListShareLinksInput { + Path: "/hello.txt", + }) + + var sharedLink string + if len(links.Links) == 0 { + sl := CreateSharedLinkInput{ Path: "/hello.txt" } + + link, err := c.Sharing.CreateSharedLink(&sl) + + assert.NoError(t, err, "revoke shared link") + sharedLink = link.URL + } else { + sharedLink = links.Links[0].URL + } + + err = c.Sharing.RevokeSharedLink(&RevokeSharedLinkInput{ + Url: sharedLink, + }) + + assert.NoError(t, err, "revoke shared link") +} \ No newline at end of file