Skip to content

Commit a516802

Browse files
authored
Use case-insensitive comparison for success case (Azure#17773)
* Use case-insensitive comparison for success case * update test
1 parent bf5fa70 commit a516802

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

sdk/azcore/internal/pollers/armloc/loc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (p *Poller) URL() string {
6262

6363
// State returns the current state of the LRO.
6464
func (p *Poller) State() pollers.OperationState {
65-
if p.CurState == pollers.StatusSucceeded {
65+
if pollers.Succeeded(p.CurState) {
6666
return pollers.OperationStateSucceeded
6767
} else if pollers.IsTerminalState(p.CurState) {
6868
return pollers.OperationStateFailed

sdk/azcore/internal/pollers/async/async.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func New(resp *http.Response, finalState pollers.FinalStateVia, pollerID string)
8787

8888
// State returns the current state of the LRO.
8989
func (p *Poller) State() pollers.OperationState {
90-
if p.CurState == pollers.StatusSucceeded {
90+
if pollers.Succeeded(p.CurState) {
9191
return pollers.OperationStateSucceeded
9292
} else if pollers.IsTerminalState(p.CurState) {
9393
return pollers.OperationStateFailed

sdk/azcore/internal/pollers/body/body.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (p *Poller) URL() string {
7575

7676
// State returns the current state of the LRO.
7777
func (p *Poller) State() pollers.OperationState {
78-
if p.CurState == pollers.StatusSucceeded {
78+
if pollers.Succeeded(p.CurState) {
7979
return pollers.OperationStateSucceeded
8080
} else if pollers.IsTerminalState(p.CurState) {
8181
return pollers.OperationStateFailed

sdk/azcore/internal/pollers/op/op.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (p *Poller) URL() string {
8383

8484
// State returns the current state of the LRO.
8585
func (p *Poller) State() pollers.OperationState {
86-
if p.CurState == pollers.StatusSucceeded {
86+
if pollers.Succeeded(p.CurState) {
8787
return pollers.OperationStateSucceeded
8888
} else if pollers.IsTerminalState(p.CurState) {
8989
return pollers.OperationStateFailed

sdk/azcore/internal/pollers/op/op_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestUpdateSucceeded(t *testing.T) {
167167
if u := poller.URL(); u != fakePollingURL2 {
168168
t.Fatalf("unexpected URL %s", u)
169169
}
170-
resp = createResponse(strings.NewReader(`{ "status": "Succeeded" }`))
170+
resp = createResponse(strings.NewReader(`{ "status": "succeeded" }`))
171171
if err := poller.Update(resp); err != nil {
172172
t.Fatal(err)
173173
}
@@ -184,7 +184,7 @@ func TestUpdateResourceLocation(t *testing.T) {
184184
if err != nil {
185185
t.Fatal(err)
186186
}
187-
resp = createResponse(strings.NewReader(`{ "status": "Succeeded", "resourceLocation": "https://foo.bar.baz/resource2" }`))
187+
resp = createResponse(strings.NewReader(`{ "status": "succeeded", "resourceLocation": "https://foo.bar.baz/resource2" }`))
188188
if err := poller.Update(resp); err != nil {
189189
t.Fatal(err)
190190
}

sdk/azcore/internal/pollers/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func Failed(s string) bool {
7878
return strings.EqualFold(s, StatusFailed) || strings.EqualFold(s, StatusCanceled)
7979
}
8080

81+
// Succeeded returns true if the LRO's state is terminal success.
82+
func Succeeded(s string) bool {
83+
return strings.EqualFold(s, StatusSucceeded)
84+
}
85+
8186
// returns true if the LRO response contains a valid HTTP status code
8287
func StatusCodeValid(resp *http.Response) bool {
8388
return exported.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusCreated, http.StatusNoContent)

0 commit comments

Comments
 (0)