Skip to content

Commit

Permalink
Use case-insensitive comparison for success case (Azure#17773)
Browse files Browse the repository at this point in the history
* Use case-insensitive comparison for success case

* update test
  • Loading branch information
jhendrixMSFT authored Apr 29, 2022
1 parent bf5fa70 commit a516802
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sdk/azcore/internal/pollers/armloc/loc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Poller) URL() string {

// State returns the current state of the LRO.
func (p *Poller) State() pollers.OperationState {
if p.CurState == pollers.StatusSucceeded {
if pollers.Succeeded(p.CurState) {
return pollers.OperationStateSucceeded
} else if pollers.IsTerminalState(p.CurState) {
return pollers.OperationStateFailed
Expand Down
2 changes: 1 addition & 1 deletion sdk/azcore/internal/pollers/async/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func New(resp *http.Response, finalState pollers.FinalStateVia, pollerID string)

// State returns the current state of the LRO.
func (p *Poller) State() pollers.OperationState {
if p.CurState == pollers.StatusSucceeded {
if pollers.Succeeded(p.CurState) {
return pollers.OperationStateSucceeded
} else if pollers.IsTerminalState(p.CurState) {
return pollers.OperationStateFailed
Expand Down
2 changes: 1 addition & 1 deletion sdk/azcore/internal/pollers/body/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (p *Poller) URL() string {

// State returns the current state of the LRO.
func (p *Poller) State() pollers.OperationState {
if p.CurState == pollers.StatusSucceeded {
if pollers.Succeeded(p.CurState) {
return pollers.OperationStateSucceeded
} else if pollers.IsTerminalState(p.CurState) {
return pollers.OperationStateFailed
Expand Down
2 changes: 1 addition & 1 deletion sdk/azcore/internal/pollers/op/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *Poller) URL() string {

// State returns the current state of the LRO.
func (p *Poller) State() pollers.OperationState {
if p.CurState == pollers.StatusSucceeded {
if pollers.Succeeded(p.CurState) {
return pollers.OperationStateSucceeded
} else if pollers.IsTerminalState(p.CurState) {
return pollers.OperationStateFailed
Expand Down
4 changes: 2 additions & 2 deletions sdk/azcore/internal/pollers/op/op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestUpdateSucceeded(t *testing.T) {
if u := poller.URL(); u != fakePollingURL2 {
t.Fatalf("unexpected URL %s", u)
}
resp = createResponse(strings.NewReader(`{ "status": "Succeeded" }`))
resp = createResponse(strings.NewReader(`{ "status": "succeeded" }`))
if err := poller.Update(resp); err != nil {
t.Fatal(err)
}
Expand All @@ -184,7 +184,7 @@ func TestUpdateResourceLocation(t *testing.T) {
if err != nil {
t.Fatal(err)
}
resp = createResponse(strings.NewReader(`{ "status": "Succeeded", "resourceLocation": "https://foo.bar.baz/resource2" }`))
resp = createResponse(strings.NewReader(`{ "status": "succeeded", "resourceLocation": "https://foo.bar.baz/resource2" }`))
if err := poller.Update(resp); err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/azcore/internal/pollers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func Failed(s string) bool {
return strings.EqualFold(s, StatusFailed) || strings.EqualFold(s, StatusCanceled)
}

// Succeeded returns true if the LRO's state is terminal success.
func Succeeded(s string) bool {
return strings.EqualFold(s, StatusSucceeded)
}

// returns true if the LRO response contains a valid HTTP status code
func StatusCodeValid(resp *http.Response) bool {
return exported.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusCreated, http.StatusNoContent)
Expand Down

0 comments on commit a516802

Please sign in to comment.