-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb35697
commit c061203
Showing
2 changed files
with
128 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,104 @@ | ||
package ddb | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
) | ||
|
||
type fakeRetryer struct { | ||
Name string | ||
} | ||
|
||
func (r *fakeRetryer) ShouldRetry(err error) bool { | ||
r.Name = "fakeRetryer" | ||
return false | ||
} | ||
|
||
func TestNewCheckpoint(t *testing.T) { | ||
c, err := New("", "") | ||
if c == nil { | ||
t.Errorf("expected checkpoint client instance. got %v", c) | ||
} | ||
if err != nil { | ||
t.Errorf("new checkpoint error expected nil. got %v", err) | ||
} | ||
} | ||
|
||
func TestCheckpointSetting(t *testing.T) { | ||
var ck Checkpoint | ||
ckPtr := &ck | ||
|
||
// Test WithMaxInterval | ||
setInterval := WithMaxInterval(time.Duration(2 * time.Minute)) | ||
setInterval(ckPtr) | ||
|
||
// Test WithRetryer | ||
var r fakeRetryer | ||
setRetryer := WithRetryer(&r) | ||
setRetryer(ckPtr) | ||
|
||
// Test WithDyanmoDBClient | ||
var fakeDbClient = dynamodb.New( | ||
session.New(aws.NewConfig()), &aws.Config{ | ||
Region: aws.String("us-west-2"), | ||
}, | ||
) | ||
setDDBClient := WithDynamoClient(fakeDbClient) | ||
setDDBClient(ckPtr) | ||
|
||
if ckPtr.maxInterval != time.Duration(2*time.Minute) { | ||
t.Errorf("new checkpoint maxInterval expected 2 minute. got %v", ckPtr.maxInterval) | ||
} | ||
if ckPtr.retryer.ShouldRetry(nil) != false { | ||
t.Errorf("new checkpoint retryer ShouldRetry always returns %v . got %v", false, ckPtr.retryer.ShouldRetry(nil)) | ||
} | ||
if ckPtr.client != fakeDbClient { | ||
t.Errorf("new checkpoint dynamodb client reference should be %p. got %v", &fakeDbClient, ckPtr.client) | ||
} | ||
} | ||
|
||
func TestNewCheckpointWithOptions(t *testing.T) { | ||
// Test WithMaxInterval | ||
setInterval := WithMaxInterval(time.Duration(2 * time.Minute)) | ||
|
||
// Test WithRetryer | ||
var r fakeRetryer | ||
setRetryer := WithRetryer(&r) | ||
|
||
// Test WithDyanmoDBClient | ||
var fakeDbClient = dynamodb.New( | ||
session.New(aws.NewConfig()), &aws.Config{ | ||
Region: aws.String("us-west-2"), | ||
}, | ||
) | ||
setDDBClient := WithDynamoClient(fakeDbClient) | ||
|
||
ckPtr, err := New("testapp", "testtable", setInterval, setRetryer, setDDBClient) | ||
if ckPtr == nil { | ||
t.Errorf("expected checkpoint client instance. got %v", ckPtr) | ||
} | ||
if err != nil { | ||
t.Errorf("new checkpoint error expected nil. got %v", err) | ||
} | ||
if ckPtr.appName != "testapp" { | ||
t.Errorf("new checkpoint app name expected %v. got %v", "testapp", ckPtr.appName) | ||
} | ||
if ckPtr.tableName != "testtable" { | ||
t.Errorf("new checkpoint table expected %v. got %v", "testtable", ckPtr.maxInterval) | ||
} | ||
|
||
if ckPtr.maxInterval != time.Duration(2*time.Minute) { | ||
t.Errorf("new checkpoint maxInterval expected 2 minute. got %v", ckPtr.maxInterval) | ||
} | ||
if ckPtr.retryer.ShouldRetry(nil) != false { | ||
t.Errorf("new checkpoint retryer ShouldRetry always returns %v . got %v", false, ckPtr.retryer.ShouldRetry(nil)) | ||
} | ||
if ckPtr.client != fakeDbClient { | ||
t.Errorf("new checkpoint dynamodb client reference should be %p. got %v", &fakeDbClient, ckPtr.client) | ||
} | ||
|
||
} |
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,24 @@ | ||
package ddb | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
) | ||
|
||
func TestDefaultRetyer(t *testing.T) { | ||
retryableError := awserr.New(dynamodb.ErrCodeProvisionedThroughputExceededException, "error is retryable", errors.New("don't care what is here")) | ||
// retryer is not nil and should returns according to what error is passed in. | ||
q := &DefaultRetryer{} | ||
if q.ShouldRetry(retryableError) != true { | ||
t.Errorf("expected ShouldRetry returns %v. got %v", false, q.ShouldRetry(retryableError)) | ||
} | ||
|
||
nonRetryableError := awserr.New(dynamodb.ErrCodeBackupInUseException, "error is not retryable", errors.New("don't care what is here")) | ||
shouldRetry := q.ShouldRetry(nonRetryableError) | ||
if shouldRetry != false { | ||
t.Errorf("expected ShouldRetry returns %v. got %v", true, shouldRetry) | ||
} | ||
} |