Skip to content

Commit

Permalink
Merge pull request #119 from magodo/share_delete_snapshot
Browse files Browse the repository at this point in the history
share change `deleteSnapshot` from bool to enum, to support `include` and `include-leased`
  • Loading branch information
tombuildsstuff authored Nov 21, 2024
2 parents bfa939f + 4f87062 commit 87a7741
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions storage/2023-11-03/file/shares/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ type DeleteResponse struct {
HttpResponse *http.Response
}

type DeleteSnapshotsType string

const (
DeleteSnapshotsInclude DeleteSnapshotsType = "include"
DeleteSnapshotsIncludeLeased DeleteSnapshotsType = "leased"
)

type DeleteInput struct {
DeleteSnapshots bool
DeleteSnapshotsType DeleteSnapshotsType
}

// Delete deletes the specified Storage Share from within a Storage Account
Expand All @@ -37,7 +44,7 @@ func (c Client) Delete(ctx context.Context, shareName string, input DeleteInput)
},
HttpMethod: http.MethodDelete,
OptionsObject: DeleteOptions{
deleteSnapshots: input.DeleteSnapshots,
deleteSnapshotsType: input.DeleteSnapshotsType,
},
Path: fmt.Sprintf("/%s", shareName),
}
Expand All @@ -61,13 +68,13 @@ func (c Client) Delete(ctx context.Context, shareName string, input DeleteInput)
}

type DeleteOptions struct {
deleteSnapshots bool
deleteSnapshotsType DeleteSnapshotsType
}

func (d DeleteOptions) ToHeaders() *client.Headers {
headers := &client.Headers{}
if d.deleteSnapshots {
headers.Append("x-ms-delete-snapshots", "include")
if d.deleteSnapshotsType != "" {
headers.Append("x-ms-delete-snapshots", string(d.deleteSnapshotsType))
}
return headers
}
Expand Down
6 changes: 3 additions & 3 deletions storage/2023-11-03/file/shares/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestSharesLifecycle(t *testing.T) {
t.Fatalf("Expected 2 identifiers but got %d", len(acls.SignedIdentifiers))
}

_, err = sharesClient.Delete(ctx, shareName, DeleteInput{DeleteSnapshots: false})
_, err = sharesClient.Delete(ctx, shareName, DeleteInput{})
if err != nil {
t.Fatalf("Error deleting Share: %s", err)
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestSharesLifecycleLargeQuota(t *testing.T) {
t.Fatalf("Expected 2 identifiers but got %d", len(acls.SignedIdentifiers))
}

_, err = sharesClient.Delete(ctx, shareName, DeleteInput{DeleteSnapshots: false})
_, err = sharesClient.Delete(ctx, shareName, DeleteInput{})
if err != nil {
t.Fatalf("Error deleting Share: %s", err)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestSharesLifecycleNFSProtocol(t *testing.T) {
t.Fatalf(`Expected enabled protocol to be "NFS" but got: %q`, share.EnabledProtocol)
}

_, err = sharesClient.Delete(ctx, shareName, DeleteInput{DeleteSnapshots: false})
_, err = sharesClient.Delete(ctx, shareName, DeleteInput{})
if err != nil {
t.Fatalf("Error deleting Share: %s", err)
}
Expand Down

0 comments on commit 87a7741

Please sign in to comment.