-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling when TTL is invalid (#106)
* Include a better error message if TTL is too large * Don't print usage on error * Allow ambiguous TTL error
- Loading branch information
1 parent
a8c2d4b
commit 14540c4
Showing
8 changed files
with
122 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_tryParseTimeToLiveError(t *testing.T) { | ||
t.Run("UnambiguousAmount", func(t *testing.T) { | ||
validationError := awserr.New("ValidationError", "1 validation error detected: Value '86400' at 'durationSeconds' failed to satisfy constraint: Member must have value less than or equal to 43200", nil) | ||
err, ok := tryParseTimeToLiveError(validationError) | ||
|
||
require.True(t, ok) | ||
require.NotNil(t, err) | ||
require.Equal(t, err.Error(), "you requested a TTL of 24 hours, but the maximum for this configuration is 12 hours") | ||
var ttlError TimeToLiveError | ||
require.ErrorAs(t, err, &ttlError) | ||
require.Equal(t, ttlError.MaxDuration, 43200*time.Second) | ||
require.Equal(t, ttlError.RequestedDuration, 86400*time.Second) | ||
require.Equal(t, ttlError.Code(), ExitCodeValueError) | ||
}) | ||
|
||
t.Run("AmbiguousAmount", func(t *testing.T) { | ||
validationError := awserr.New("ValidationError", "The requested DurationSeconds exceeds the MaxSessionDuration set for this role.", nil) | ||
err, ok := tryParseTimeToLiveError(validationError) | ||
|
||
require.True(t, ok) | ||
require.NotNil(t, err) | ||
require.Equal(t, err.Error(), "the TTL you requested exceeds the maximum TTL for this configuration") | ||
var ttlError TimeToLiveError | ||
require.ErrorAs(t, err, &ttlError) | ||
require.Equal(t, ttlError.MaxDuration, time.Duration(0)) | ||
require.Equal(t, ttlError.RequestedDuration, time.Duration(0)) | ||
require.Equal(t, ttlError.Code(), ExitCodeValueError) | ||
}) | ||
} |
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