@@ -13,7 +13,7 @@ import (
13
13
14
14
"github.com/aws/aws-sdk-go/aws"
15
15
"github.com/aws/aws-sdk-go/aws/session"
16
- "github.com/aws/aws-sdk-go/service/s3"
16
+ "github.com/aws/aws-sdk-go/service/s3/s3manager "
17
17
uuid "github.com/satori/go.uuid"
18
18
"github.com/stretchr/testify/assert"
19
19
"github.com/stretchr/testify/require"
@@ -22,6 +22,7 @@ import (
22
22
var (
23
23
AthenaDatabase = "go_athena_tests"
24
24
S3Bucket = "go-athena-tests"
25
+ AwsRegion = "us-east-1"
25
26
)
26
27
27
28
func init () {
@@ -32,11 +33,18 @@ func init() {
32
33
if v := os .Getenv ("S3_BUCKET" ); v != "" {
33
34
S3Bucket = v
34
35
}
36
+
37
+ if v := os .Getenv ("AWS_DEFAULT_REGION" ); v != "" {
38
+ AwsRegion = v
39
+ }
40
+ if v := os .Getenv ("ATHENA_REGION" ); v != "" {
41
+ AwsRegion = v
42
+ }
35
43
}
36
44
37
45
func TestQuery (t * testing.T ) {
38
46
harness := setup (t )
39
- // defer harness.teardown()
47
+ defer harness .teardown ()
40
48
41
49
expected := []dummyRow {
42
50
{
@@ -115,8 +123,13 @@ func TestQuery(t *testing.T) {
115
123
}
116
124
117
125
func TestOpen (t * testing.T ) {
126
+ var acfg []* aws.Config
127
+ acfg = append (acfg , & aws.Config {Region : aws .String (AwsRegion )})
128
+ session , err := session .NewSession (acfg ... )
129
+ require .NoError (t , err , "Query" )
130
+
118
131
db , err := Open (Config {
119
- Session : session . Must ( session . NewSession ()) ,
132
+ Session : session ,
120
133
Database : AthenaDatabase ,
121
134
OutputLocation : fmt .Sprintf ("s3://%s/noop" , S3Bucket ),
122
135
})
@@ -164,16 +177,23 @@ type dummyRow struct {
164
177
type athenaHarness struct {
165
178
t * testing.T
166
179
db * sql.DB
167
- s3 * s3. S3
180
+ sess * session. Session
168
181
169
182
table string
170
183
}
171
184
172
185
func setup (t * testing.T ) * athenaHarness {
173
- harness := athenaHarness {t : t , s3 : s3 .New (session .New ())}
186
+ var acfg []* aws.Config
187
+ acfg = append (acfg , & aws.Config {
188
+ Region : aws .String (AwsRegion ),
189
+ })
190
+ sess , err := session .NewSession (acfg ... )
191
+ if err != nil {
192
+ require .NoError (t , err )
193
+ }
194
+ harness := athenaHarness {t : t , sess : sess }
174
195
175
- var err error
176
- harness .db , err = sql .Open ("athena" , fmt .Sprintf ("db=%s&output_location=s3://%s/output" , AthenaDatabase , S3Bucket ))
196
+ harness .db , err = sql .Open ("athena" , fmt .Sprintf ("db=%s&output_location=s3://%s/output®ion=%s" , AthenaDatabase , S3Bucket , AwsRegion ))
177
197
require .NoError (t , err )
178
198
179
199
harness .setupTable ()
@@ -230,7 +250,9 @@ func (a *athenaHarness) uploadData(rows []dummyRow) {
230
250
require .NoError (a .t , err )
231
251
}
232
252
233
- _ , err := a .s3 .PutObject (& s3.PutObjectInput {
253
+ uploader := s3manager .NewUploader (a .sess )
254
+
255
+ _ , err := uploader .Upload (& s3manager.UploadInput {
234
256
Bucket : aws .String (S3Bucket ),
235
257
Key : aws .String (fmt .Sprintf ("%s/fixture.json" , a .table )),
236
258
Body : bytes .NewReader (buf .Bytes ()),
0 commit comments