Skip to content

Commit

Permalink
implement stringify on go-autorest/autorest/azure.Resource (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
haitch authored Nov 9, 2020
1 parent bf140ad commit f7ec17d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autorest/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ type Resource struct {
ResourceName string
}

// String function returns a string in form of azureResourceID
func (r Resource) String() string {
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/%s/%s/%s", r.SubscriptionID, r.ResourceGroup, r.Provider, r.ResourceType, r.ResourceName)
}

// ParseResourceID parses a resource ID into a ResourceDetails struct.
// See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-resource#return-value-4.
func ParseResourceID(resourceID string) (Resource, error) {
Expand Down
7 changes: 7 additions & 0 deletions autorest/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"reflect"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -544,6 +545,12 @@ func TestParseResourceID_WithValidBasicResourceID(t *testing.T) {
t.Logf("got: %+v\nwant: %+v", got, want)
t.Fail()
}

reGenResourceID := got.String()
if !strings.EqualFold(basicResourceID, reGenResourceID) {
t.Logf("got: %+v\nwant: %+v", reGenResourceID, basicResourceID)
t.Fail()
}
}

func TestParseResourceID_WithValidSubResourceID(t *testing.T) {
Expand Down

0 comments on commit f7ec17d

Please sign in to comment.