-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a helper for checking no responses
- Loading branch information
1 parent
d3e94dd
commit 278ec58
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package azurerm | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/Azure/go-autorest/autorest" | ||
) | ||
|
||
func responseWasNotFound(resp autorest.Response) bool { | ||
if r := resp.Response; r != nil { | ||
if r.StatusCode == http.StatusNotFound { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package azurerm | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Azure/go-autorest/autorest" | ||
) | ||
|
||
func TestResponseNotFound_DroppedConnection(t *testing.T) { | ||
resp := autorest.Response{} | ||
if responseWasNotFound(resp) { | ||
t.Fatalf("responseWasNotFound should return `false` for a dropped connection") | ||
} | ||
} | ||
|
||
func TestResponseNotFound_StatusCodes(t *testing.T) { | ||
testCases := []struct { | ||
statusCode int | ||
expectedResult bool | ||
}{ | ||
{ http.StatusOK, false, }, | ||
{ http.StatusInternalServerError, false }, | ||
{ http.StatusNotFound, true }, | ||
} | ||
|
||
for _, test := range testCases { | ||
resp := autorest.Response{ | ||
Response: &http.Response{ | ||
StatusCode: test.statusCode, | ||
}, | ||
} | ||
result := responseWasNotFound(resp) | ||
if test.expectedResult != result { | ||
t.Fatalf("Expected '%+v' for status code '%d' - got '%+v'", | ||
test.expectedResult, test.statusCode, result) | ||
} | ||
} | ||
} |