-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move error functions out of package.go (#502)
This moves some private error-related functions out of `provider.go` into a separate package so that resources and data sources aren't unnecessarily tied to the provider code file.
- Loading branch information
Showing
10 changed files
with
89 additions
and
80 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
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
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
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
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
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
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
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
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
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,49 @@ | ||
package errors | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/equinix/rest-go" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProvider_HasApplicationErrorCode(t *testing.T) { | ||
// given | ||
code := "ERR-505" | ||
errors := []rest.ApplicationError{ | ||
{ | ||
Code: "ERR-505", | ||
}, | ||
{ | ||
Code: acctest.RandString(10), | ||
}, | ||
} | ||
// when | ||
result := HasApplicationErrorCode(errors, code) | ||
// then | ||
assert.True(t, result, "Error list contains error with given code") | ||
} | ||
|
||
func TestProvider_IsRestNotFoundError(t *testing.T) { | ||
// given | ||
input := []error{ | ||
rest.Error{HTTPCode: http.StatusNotFound, Message: "Not Found"}, | ||
rest.Error{HTTPCode: http.StatusInternalServerError, Message: "Internal Server Error"}, | ||
fmt.Errorf("some bogus error"), | ||
} | ||
expected := []bool{ | ||
true, | ||
false, | ||
false, | ||
} | ||
// when | ||
result := make([]bool, len(input)) | ||
for i := range input { | ||
result[i] = IsRestNotFoundError(input[i]) | ||
} | ||
// then | ||
assert.Equal(t, expected, result, "Result matches expected output") | ||
} |