Skip to content

Commit

Permalink
Adding a helper for checking no responses
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 1, 2017
1 parent d3e94dd commit 278ec58
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions azurerm/response.go
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
}
39 changes: 39 additions & 0 deletions azurerm/response_test.go
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)
}
}
}

0 comments on commit 278ec58

Please sign in to comment.