-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter to filter cloud provider. (#765)
* Add parameter to filter cloud provider. Signed-off-by: Rodrigo Reis <[email protected]> * goimports. Signed-off-by: Rodrigo Reis <[email protected]> * typo Signed-off-by: Rodrigo Reis <[email protected]> * Use enum for parameter, improve provider naming. Signed-off-by: Rodrigo Reis <[email protected]> * Test clamped retryer. Signed-off-by: Rodrigo Reis <[email protected]> * Test copy values. Signed-off-by: Rodrigo Reis <[email protected]> * Test cluster version. Signed-off-by: Rodrigo Reis <[email protected]> * goimports. Signed-off-by: Rodrigo Reis <[email protected]> --------- Signed-off-by: Rodrigo Reis <[email protected]>
- Loading branch information
1 parent
de834d6
commit ec5b971
Showing
12 changed files
with
341 additions
and
26 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,42 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseVersion(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
version string | ||
expected string | ||
}{ | ||
{ | ||
name: "empty", | ||
version: "", | ||
expected: "#", | ||
}, | ||
{ | ||
name: "simple", | ||
version: "foo#bar", | ||
expected: "foo#bar", | ||
}, | ||
{ | ||
name: "missing hash", | ||
version: "foo", | ||
expected: "#", | ||
}, | ||
{ | ||
name: "missing version", | ||
version: "#bar", | ||
expected: "#bar", | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
version := ParseVersion(tc.version) | ||
result := version.String() | ||
require.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |
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,88 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/client/metadata" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestShouldRetry(t *testing.T) { | ||
for _, tc := range []struct { | ||
caseName string | ||
maxRetries int | ||
maxRetryInterval time.Duration | ||
request *request.Request | ||
expected bool | ||
}{ | ||
{ | ||
caseName: "should not retry", | ||
maxRetries: 1, | ||
request: &request.Request{}, | ||
expected: false, | ||
}, | ||
{ | ||
caseName: "should retry with metadata service", | ||
maxRetries: 1, | ||
request: &request.Request{ | ||
ClientInfo: metadata.ClientInfo{ | ||
ServiceName: "ec2metadata", | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
caseName: "should not retry with metadata service", | ||
maxRetries: 1, | ||
request: &request.Request{ | ||
ClientInfo: metadata.ClientInfo{ | ||
ServiceName: "ec2metadata", | ||
}, | ||
RetryCount: 8, | ||
}, | ||
expected: false, | ||
}, | ||
} { | ||
t.Run(tc.caseName, func(t *testing.T) { | ||
retryer := NewClampedRetryer(tc.maxRetries, time.Second) | ||
|
||
res := retryer.ShouldRetry(tc.request) | ||
require.Equal(t, tc.expected, res) | ||
}) | ||
} | ||
} | ||
|
||
func TestRetryRules(t *testing.T) { | ||
for _, tc := range []struct { | ||
caseName string | ||
maxRetryInterval time.Duration | ||
request *request.Request | ||
expectedLessOrEqual time.Duration | ||
}{ | ||
{ | ||
caseName: "should return max retry interval", | ||
maxRetryInterval: time.Millisecond, | ||
request: &request.Request{}, | ||
expectedLessOrEqual: time.Millisecond, | ||
}, | ||
{ | ||
caseName: "should not return max retry interval", | ||
maxRetryInterval: time.Second, | ||
request: &request.Request{ | ||
ClientInfo: metadata.ClientInfo{ | ||
ServiceName: "ec2metadata", | ||
}, | ||
}, | ||
expectedLessOrEqual: time.Second / 2, | ||
}, | ||
} { | ||
t.Run(tc.caseName, func(t *testing.T) { | ||
retryer := NewClampedRetryer(1, tc.maxRetryInterval) | ||
|
||
res := retryer.RetryRules(tc.request) | ||
require.LessOrEqual(t, res, tc.expectedLessOrEqual) | ||
}) | ||
} | ||
} |
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,38 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCopyValues(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
value map[string]interface{} | ||
}{ | ||
{ | ||
name: "empty", | ||
value: map[string]interface{}{}, | ||
}, | ||
{ | ||
name: "simple", | ||
value: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
{ | ||
name: "nested", | ||
value: map[string]interface{}{ | ||
"foo": map[string]interface{}{ | ||
"bar": "baz", | ||
}, | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := CopyValues(tc.value) | ||
require.Equal(t, tc.value, result) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.