github.com/aavshr/aws-sdk-go@v1.41.3/aws/config_test.go (about) 1 package aws 2 3 import ( 4 "net/http" 5 "reflect" 6 "testing" 7 8 "github.com/aavshr/aws-sdk-go/aws/credentials" 9 ) 10 11 var testCredentials = credentials.NewStaticCredentials("AKID", "SECRET", "SESSION") 12 13 var copyTestConfig = Config{ 14 Credentials: testCredentials, 15 Endpoint: String("CopyTestEndpoint"), 16 Region: String("COPY_TEST_AWS_REGION"), 17 DisableSSL: Bool(true), 18 HTTPClient: http.DefaultClient, 19 LogLevel: LogLevel(LogDebug), 20 Logger: NewDefaultLogger(), 21 MaxRetries: Int(3), 22 DisableParamValidation: Bool(true), 23 DisableComputeChecksums: Bool(true), 24 S3ForcePathStyle: Bool(true), 25 } 26 27 func TestCopy(t *testing.T) { 28 want := copyTestConfig 29 got := copyTestConfig.Copy() 30 if !reflect.DeepEqual(*got, want) { 31 t.Errorf("Copy() = %+v", got) 32 t.Errorf(" want %+v", want) 33 } 34 35 got.Region = String("other") 36 if got.Region == want.Region { 37 t.Errorf("Expect setting copy values not not reflect in source") 38 } 39 } 40 41 func TestCopyReturnsNewInstance(t *testing.T) { 42 want := copyTestConfig 43 got := copyTestConfig.Copy() 44 if got == &want { 45 t.Errorf("Copy() = %p; want different instance as source %p", got, &want) 46 } 47 } 48 49 var mergeTestZeroValueConfig = Config{} 50 51 var mergeTestConfig = Config{ 52 Credentials: testCredentials, 53 Endpoint: String("MergeTestEndpoint"), 54 Region: String("MERGE_TEST_AWS_REGION"), 55 DisableSSL: Bool(true), 56 HTTPClient: http.DefaultClient, 57 LogLevel: LogLevel(LogDebug), 58 Logger: NewDefaultLogger(), 59 MaxRetries: Int(10), 60 DisableParamValidation: Bool(true), 61 DisableComputeChecksums: Bool(true), 62 DisableEndpointHostPrefix: Bool(true), 63 EnableEndpointDiscovery: Bool(true), 64 EnforceShouldRetryCheck: Bool(true), 65 DisableRestProtocolURICleaning: Bool(true), 66 S3ForcePathStyle: Bool(true), 67 LowerCaseHeaderMaps: Bool(true), 68 } 69 70 var mergeTests = []struct { 71 cfg *Config 72 in *Config 73 want *Config 74 }{ 75 {&Config{}, nil, &Config{}}, 76 {&Config{}, &mergeTestZeroValueConfig, &Config{}}, 77 {&Config{}, &mergeTestConfig, &mergeTestConfig}, 78 } 79 80 func TestMerge(t *testing.T) { 81 for i, tt := range mergeTests { 82 got := tt.cfg.Copy() 83 got.MergeIn(tt.in) 84 if !reflect.DeepEqual(got, tt.want) { 85 t.Errorf("Config %d %+v", i, tt.cfg) 86 t.Errorf(" Merge(%+v)", tt.in) 87 t.Errorf(" got %+v", got) 88 t.Errorf(" want %+v", tt.want) 89 } 90 } 91 }