1package aws 2 3import ( 4 "net/http" 5 "reflect" 6 "testing" 7 8 "github.com/aws/aws-sdk-go/aws/credentials" 9) 10 11var testCredentials = credentials.NewStaticCredentials("AKID", "SECRET", "SESSION") 12 13var 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 27func 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 41func 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 49var mergeTestZeroValueConfig = Config{} 50 51var 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 S3ForcePathStyle: Bool(true), 63} 64 65var mergeTests = []struct { 66 cfg *Config 67 in *Config 68 want *Config 69}{ 70 {&Config{}, nil, &Config{}}, 71 {&Config{}, &mergeTestZeroValueConfig, &Config{}}, 72 {&Config{}, &mergeTestConfig, &mergeTestConfig}, 73} 74 75func TestMerge(t *testing.T) { 76 for i, tt := range mergeTests { 77 got := tt.cfg.Copy() 78 got.MergeIn(tt.in) 79 if !reflect.DeepEqual(got, tt.want) { 80 t.Errorf("Config %d %+v", i, tt.cfg) 81 t.Errorf(" Merge(%+v)", tt.in) 82 t.Errorf(" got %+v", got) 83 t.Errorf(" want %+v", tt.want) 84 } 85 } 86} 87