-
-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add provider cache offline errors handling (#3527)
* add offline errors handling * Improved handling of offline errors * Cleanup * Add test for handling offline errors * Linter fixes * Linter fixes * imports update
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package handlers_test | ||
|
||
import ( | ||
"errors" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terragrunt/terraform/cache/handlers" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsOfflineError(t *testing.T) { | ||
t.Parallel() | ||
testCases := []struct { | ||
err error | ||
expected bool | ||
desc string | ||
}{ | ||
{syscall.ECONNREFUSED, true, "connection refused"}, | ||
{syscall.ECONNRESET, true, "connection reset by peer"}, | ||
{syscall.ECONNABORTED, true, "connection aborted"}, | ||
{syscall.ENETUNREACH, true, "network is unreachable"}, | ||
{errors.New("get \"https://registry.terraform.io/.well-known/terraform.json\": dial tcp: lookup registry.terraform.io on 185.12.64.1:53: dial udp 185.12.64.1:53: connect: network is unreachable"), true, "network is unreachable"}, | ||
{errors.New("get \"https://registry.terraform.io/.well-known/terraform.json\": read tcp 10.10.230.10:58328->10.245.10.15:443: read: connection reset by peer"), true, "network is unreachable"}, | ||
{errors.New("random error"), false, "a random error that should not be offline"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
t.Parallel() | ||
result := handlers.IsOfflineError(tc.err) | ||
assert.Equal(t, tc.expected, result, "Expected result for %v is %v", tc.desc, tc.expected) | ||
}) | ||
} | ||
} |