Skip to content

Commit

Permalink
Fix EndpointResolverWithOptionsFunc Bug (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail authored Nov 17, 2021
1 parent fafd921 commit 613f9c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .changelog/ee24d721edd94d88826eac19451093c6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "ee24d721-edd9-4d88-826e-ac19451093c6",
"type": "bugfix",
"description": "Fixed a bug that prevented aws.EndpointResolverWithOptionsFunc from satisfying the aws.EndpointResolverWithOptions interface.",
"modules": [
"."
]
}
6 changes: 3 additions & 3 deletions aws/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ type EndpointResolverWithOptions interface {
}

// EndpointResolverWithOptionsFunc wraps a function to satisfy the EndpointResolverWithOptions interface.
type EndpointResolverWithOptionsFunc func(service, region string, options interface{}) (Endpoint, error)
type EndpointResolverWithOptionsFunc func(service, region string, options ...interface{}) (Endpoint, error)

// ResolveEndpoint calls the wrapped function and returns the results.
func (e EndpointResolverWithOptionsFunc) ResolveEndpoint(service, region string, options interface{}) (Endpoint, error) {
return e(service, region, options)
func (e EndpointResolverWithOptionsFunc) ResolveEndpoint(service, region string, options ...interface{}) (Endpoint, error) {
return e(service, region, options...)
}

// GetDisableHTTPS takes a service's EndpointResolverOptions and returns the DisableHTTPS value.
Expand Down
28 changes: 28 additions & 0 deletions aws/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,31 @@ func TestGetUseFIPSEndpoint(t *testing.T) {
})
}
}

var _ EndpointResolverWithOptions = EndpointResolverWithOptionsFunc(nil)

func TestEndpointResolverWithOptionsFunc_ResolveEndpoint(t *testing.T) {
var er EndpointResolverWithOptions = EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (Endpoint, error) {
if e, a := "foo", service; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", region; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 2, len(options); e != a {
t.Errorf("expect %v, got %v", e, a)
}
return Endpoint{
URL: "https://foo.amazonaws.com",
}, nil
})

e, err := er.ResolveEndpoint("foo", "bar", 1, 2)
if err != nil {
t.Errorf("expect no error, got %v", err)
}

if e,a := "https://foo.amazonaws.com", e.URL; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}

0 comments on commit 613f9c9

Please sign in to comment.