@@ -11,9 +11,9 @@ import (
1111 "testing"
1212 "time"
1313
14- "github.com/aws/aws-sdk-go/aws"
15- "github.com/aws/aws-sdk-go/aws/session "
16- "github.com/aws/aws-sdk-go/service/s3"
14+ "github.com/aws/aws-sdk-go-v2 /aws"
15+ "github.com/aws/aws-sdk-go-v2/config "
16+ "github.com/aws/aws-sdk-go-v2 /service/s3"
1717 uuid "github.com/satori/go.uuid"
1818 "github.com/stretchr/testify/assert"
1919 "github.com/stretchr/testify/require"
@@ -35,8 +35,9 @@ func init() {
3535}
3636
3737func TestQuery (t * testing.T ) {
38- harness := setup (t )
39- // defer harness.teardown()
38+ ctx := context .Background ()
39+ harness := setup (ctx , t )
40+ // defer harness.teardown(ctx)
4041
4142 expected := []dummyRow {
4243 {
@@ -77,9 +78,9 @@ func TestQuery(t *testing.T) {
7778 },
7879 }
7980 expectedTypeNames := []string {"varchar" , "smallint" , "integer" , "bigint" , "boolean" , "float" , "double" , "varchar" , "timestamp" , "date" , "decimal" }
80- harness .uploadData (expected )
81+ harness .uploadData (ctx , expected )
8182
82- rows := harness .mustQuery ("select * from %s" , harness .table )
83+ rows := harness .mustQuery (ctx , "select * from %s" , harness .table )
8384 index := - 1
8485 for rows .Next () {
8586 index ++
@@ -115,8 +116,10 @@ func TestQuery(t *testing.T) {
115116}
116117
117118func TestOpen (t * testing.T ) {
118- db , err := Open (Config {
119- Session : session .Must (session .NewSession ()),
119+ awsConfig , err := config .LoadDefaultConfig (context .Background ())
120+ require .NoError (t , err , "LoadDefaultConfig" )
121+ db , err := Open (DriverConfig {
122+ Config : & awsConfig ,
120123 Database : AthenaDatabase ,
121124 OutputLocation : fmt .Sprintf ("s3://%s/noop" , S3Bucket ),
122125 })
@@ -143,28 +146,29 @@ type dummyRow struct {
143146type athenaHarness struct {
144147 t * testing.T
145148 db * sql.DB
146- s3 * s3.S3
149+ s3 * s3.Client
147150
148151 table string
149152}
150153
151- func setup (t * testing.T ) * athenaHarness {
152- harness := athenaHarness {t : t , s3 : s3 .New (session .New ())}
154+ func setup (ctx context.Context , t * testing.T ) * athenaHarness {
155+ awsConfig , err := config .LoadDefaultConfig (ctx )
156+ require .NoError (t , err )
157+ harness := athenaHarness {t : t , s3 : s3 .NewFromConfig (awsConfig )}
153158
154- var err error
155159 harness .db , err = sql .Open ("athena" , fmt .Sprintf ("db=%s&output_location=s3://%s/output" , AthenaDatabase , S3Bucket ))
156160 require .NoError (t , err )
157161
158- harness .setupTable ()
162+ harness .setupTable (ctx )
159163
160164 return & harness
161165}
162166
163- func (a * athenaHarness ) setupTable () {
167+ func (a * athenaHarness ) setupTable (ctx context. Context ) {
164168 // tables cannot start with numbers or contain dashes
165169 id := uuid .NewV4 ()
166170 a .table = "t_" + strings .Replace (id .String (), "-" , "_" , - 1 )
167- a .mustExec (`CREATE EXTERNAL TABLE %[1]s (
171+ a .mustExec (ctx , `CREATE EXTERNAL TABLE %[1]s (
168172 nullValue string,
169173 smallintType smallint,
170174 intType int,
@@ -184,32 +188,32 @@ WITH SERDEPROPERTIES (
184188 fmt .Printf ("created table: %s" , a .table )
185189}
186190
187- func (a * athenaHarness ) teardown () {
188- a .mustExec ("drop table %s" , a .table )
191+ func (a * athenaHarness ) teardown (ctx context. Context ) {
192+ a .mustExec (ctx , "drop table %s" , a .table )
189193}
190194
191- func (a * athenaHarness ) mustExec (sql string , args ... interface {}) {
195+ func (a * athenaHarness ) mustExec (ctx context. Context , sql string , args ... interface {}) {
192196 query := fmt .Sprintf (sql , args ... )
193- _ , err := a .db .ExecContext (context . TODO () , query )
197+ _ , err := a .db .ExecContext (ctx , query )
194198 require .NoError (a .t , err , query )
195199}
196200
197- func (a * athenaHarness ) mustQuery (sql string , args ... interface {}) * sql.Rows {
201+ func (a * athenaHarness ) mustQuery (ctx context. Context , sql string , args ... interface {}) * sql.Rows {
198202 query := fmt .Sprintf (sql , args ... )
199- rows , err := a .db .QueryContext (context . TODO () , query )
203+ rows , err := a .db .QueryContext (ctx , query )
200204 require .NoError (a .t , err , query )
201205 return rows
202206}
203207
204- func (a * athenaHarness ) uploadData (rows []dummyRow ) {
208+ func (a * athenaHarness ) uploadData (ctx context. Context , rows []dummyRow ) {
205209 var buf bytes.Buffer
206210 enc := json .NewEncoder (& buf )
207211 for _ , row := range rows {
208212 err := enc .Encode (row )
209213 require .NoError (a .t , err )
210214 }
211215
212- _ , err := a .s3 .PutObject (& s3.PutObjectInput {
216+ _ , err := a .s3 .PutObject (ctx , & s3.PutObjectInput {
213217 Bucket : aws .String (S3Bucket ),
214218 Key : aws .String (fmt .Sprintf ("%s/fixture.json" , a .table )),
215219 Body : bytes .NewReader (buf .Bytes ()),
0 commit comments