-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathendpoints_config_test.go
139 lines (125 loc) · 3.65 KB
/
endpoints_config_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Code generated by smithy-go-codegen DO NOT EDIT.
package ssooidc
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"os"
"reflect"
"testing"
)
type mockConfigSource struct {
global string
service string
ignore bool
}
// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
// endpoints feature.
func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) {
return m.ignore, m.ignore, nil
}
// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use
// with configured endpoints.
func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) {
if m.service != "" {
return m.service, true, nil
}
return "", false, nil
}
func TestResolveBaseEndpoint(t *testing.T) {
cases := map[string]struct {
envGlobal string
envService string
envIgnore bool
configGlobal string
configService string
configIgnore bool
clientEndpoint *string
expectURL *string
}{
"env ignore": {
envGlobal: "https://env-global.dev",
envService: "https://env-sso-oidc.dev",
envIgnore: true,
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
expectURL: nil,
},
"env global": {
envGlobal: "https://env-global.dev",
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
expectURL: aws.String("https://env-global.dev"),
},
"env service": {
envGlobal: "https://env-global.dev",
envService: "https://env-sso-oidc.dev",
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
expectURL: aws.String("https://env-sso-oidc.dev"),
},
"config ignore": {
envGlobal: "https://env-global.dev",
envService: "https://env-sso-oidc.dev",
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
configIgnore: true,
expectURL: nil,
},
"config global": {
configGlobal: "http://config-global.dev",
expectURL: aws.String("http://config-global.dev"),
},
"config service": {
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
expectURL: aws.String("http://config-sso-oidc.dev"),
},
"client": {
envGlobal: "https://env-global.dev",
envService: "https://env-sso-oidc.dev",
configGlobal: "http://config-global.dev",
configService: "http://config-sso-oidc.dev",
clientEndpoint: aws.String("https://client-sso-oidc.dev"),
expectURL: aws.String("https://client-sso-oidc.dev"),
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
os.Clearenv()
awsConfig := aws.Config{}
ignore := c.envIgnore || c.configIgnore
if c.configGlobal != "" && !ignore {
awsConfig.BaseEndpoint = aws.String(c.configGlobal)
}
if c.envGlobal != "" {
t.Setenv("AWS_ENDPOINT_URL", c.envGlobal)
if !ignore {
awsConfig.BaseEndpoint = aws.String(c.envGlobal)
}
}
if c.envService != "" {
t.Setenv("AWS_ENDPOINT_URL_SSO_OIDC", c.envService)
}
awsConfig.ConfigSources = []interface{}{
mockConfigSource{
global: c.envGlobal,
service: c.envService,
ignore: c.envIgnore,
},
mockConfigSource{
global: c.configGlobal,
service: c.configService,
ignore: c.configIgnore,
},
}
client := NewFromConfig(awsConfig, func(o *Options) {
if c.clientEndpoint != nil {
o.BaseEndpoint = c.clientEndpoint
}
})
if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) {
t.Errorf("expect endpoint %v , got %v", e, a)
}
})
}
}