Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/endpoints: Update unit tests use static data instead of live model #4389

Merged
merged 2 commits into from May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions aws/endpoints/endpoints_test.go
Expand Up @@ -5,6 +5,12 @@ package endpoints

import "testing"

// ***************************************************************************
// All endpoint metadata is sourced from the testdata/endpoints.json file at
// test startup. Not the live endpoints model file. Update the testdata file
// for the tests to use the latest live model.
// ***************************************************************************

func TestEnumDefaultPartitions(t *testing.T) {
resolver := DefaultResolver()
enum, ok := resolver.(EnumPartitions)
Expand Down
10 changes: 9 additions & 1 deletion aws/endpoints/example_test.go
Expand Up @@ -13,6 +13,12 @@ import (
"github.com/aws/aws-sdk-go/service/sqs"
)

// ***************************************************************************
// All endpoint metadata is sourced from the testdata/endpoints.json file at
// test startup. Not the live endpoints model file. Update the testdata file
// for the tests to use the latest live model.
// ***************************************************************************

func ExampleEnumPartitions() {
resolver := endpoints.DefaultResolver()
partitions := resolver.(endpoints.EnumPartitions).Partitions()
Expand All @@ -31,7 +37,9 @@ func ExampleEnumPartitions() {
}

func ExampleResolverFunc() {
myCustomResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
myCustomResolver := func(service, region string, optFns ...func(*endpoints.Options)) (
endpoints.ResolvedEndpoint, error,
) {
if service == endpoints.S3ServiceID {
return endpoints.ResolvedEndpoint{
URL: "s3.custom.endpoint.com",
Expand Down
49 changes: 49 additions & 0 deletions aws/endpoints/main_test.go
@@ -0,0 +1,49 @@
package endpoints

import (
"fmt"
"os"
"path/filepath"
"testing"
)

// Update all endpoints partition variables data to be the static testdata
// model instead of the dynamic live model. This ensures that endpoint tests
// are tested against static data, and will not break when the live
// endpoints.json model is updated.

func TestMain(m *testing.M) {
testdataFilename := filepath.Join("testdata", "endpoints.json")

testdataFile, err := os.Open(testdataFilename)
if err != nil {
panic(fmt.Sprintf("failed to open test endpoints model, %v", err))
}

resolver, err := DecodeModel(testdataFile)
if err != nil {
panic(fmt.Sprintf("failed to decode test endpoints model, %v", err))
}

partitions, ok := resolver.(partitions)
if !ok {
panic(fmt.Sprintf("expect %T resolver, got %T", partitions, resolver))
}

for _, p := range partitions {
switch p.ID {
case "aws":
awsPartition = p
case "aws-cn":
awscnPartition = p
case "aws-us-gov":
awsusgovPartition = p
case "aws-iso":
awsisoPartition = p
case "aws-iso-b":
awsisobPartition = p
default:
panic("unknown endpoints partition " + p.ID)
}
}
}