-
Notifications
You must be signed in to change notification settings - Fork 811
Expand file tree
/
Copy pathsession_test.go
More file actions
53 lines (43 loc) · 1.39 KB
/
session_test.go
File metadata and controls
53 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package awssession
import (
"context"
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/stretchr/testify/assert"
)
func TestHttpTimeoutReturnDefault(t *testing.T) {
os.Setenv(httpTimeoutEnv, "2")
defer os.Unsetenv(httpTimeoutEnv)
expectedHTTPTimeOut := time.Duration(10) * time.Second
assert.Equal(t, expectedHTTPTimeOut, getHTTPTimeout())
}
func TestHttpTimeoutWithValueAbove10(t *testing.T) {
os.Setenv(httpTimeoutEnv, "12")
defer os.Unsetenv(httpTimeoutEnv)
expectedHTTPTimeOut := time.Duration(12) * time.Second
assert.Equal(t, expectedHTTPTimeOut, getHTTPTimeout())
}
func TestAwsEc2EndpointResolver(t *testing.T) {
customEndpoint := "https://ec2.us-west-2.customaws.com"
ctx := context.Background()
os.Setenv("AWS_EC2_ENDPOINT", customEndpoint)
defer os.Unsetenv("AWS_EC2_ENDPOINT")
cfg, err := New(ctx)
assert.NoError(t, err)
resolvedEndpoint, err := cfg.EndpointResolver.ResolveEndpoint(ec2.ServiceID, "")
assert.NoError(t, err)
assert.Equal(t, customEndpoint, resolvedEndpoint.URL)
}
func TestNew_SetsHTTPClientTimeout(t *testing.T) {
t.Setenv("AWS_REGION", "us-west-2")
cfg, err := New(context.Background())
assert.NoError(t, err)
assert.NotNil(t, cfg.HTTPClient)
}
func TestNewAWSSDKHTTPClient_SetsTimeout(t *testing.T) {
client := NewAWSSDKHTTPClient()
assert.NotNil(t, client)
assert.Equal(t, DefaultAWSSDKClientTimeout, client.Timeout)
}