@@ -39,11 +39,11 @@ const (
3939// helper functions
4040
4141func setAwsEnv () {
42- os .Setenv ("AWS_REGION" , testRegion )
43- os .Setenv ("AWS_SECRET_ACCESS_KEY" , "test" )
44- os .Setenv ("AWS_ACCESS_KEY_ID" , "test" )
45- os .Setenv ("AWS_ENDPOINT_URL" , customAWSEndpoint )
46- os .Setenv ("AWS_S3_DISABLE_CHECKSUM" , "true" )
42+ _ = os .Setenv ("AWS_REGION" , testRegion )
43+ _ = os .Setenv ("AWS_SECRET_ACCESS_KEY" , "test" )
44+ _ = os .Setenv ("AWS_ACCESS_KEY_ID" , "test" )
45+ _ = os .Setenv ("AWS_ENDPOINT_URL" , customAWSEndpoint )
46+ _ = os .Setenv ("AWS_S3_DISABLE_CHECKSUM" , "true" )
4747}
4848
4949func setup () {
@@ -79,21 +79,21 @@ func teardown() {
7979
8080func awsCmdPopulateBucket () {
8181 // create test data
82- tmpDir , _ := os .MkdirTemp ("" , "" )
83- defer os .RemoveAll (tmpDir )
82+ testFile , _ := os .CreateTemp ("" , "data-*.txt" )
83+ defer func () {
84+ _ = os .Remove (testFile .Name ())
85+ }()
8486
85- testDataFilepath := filepath .Join (tmpDir , "data.txt" )
86- testFile , _ := os .Create (testDataFilepath )
8787 _ , _ = testFile .WriteString (testObjectData )
88- testFile .Close ()
88+ _ = testFile .Close ()
8989
9090 // populate bucket
91- if err := exec .Command (
91+ if err := exec .Command ( //nolint:gosec
9292 "aws" , "s3api" ,
9393 "put-object" ,
9494 "--bucket" , testBucket ,
9595 "--key" , testObjectKey ,
96- "--body" , testDataFilepath ,
96+ "--body" , testFile . Name () ,
9797 "--metadata" , fmt .Sprintf ("%v=%v" , testMetaKey , testMetaValue ),
9898 ).Run (); err != nil {
9999
@@ -102,7 +102,7 @@ func awsCmdPopulateBucket() {
102102}
103103
104104func awsCmdBucketExists (bucket string ) bool {
105- if err := exec .Command (
105+ if err := exec .Command ( //nolint:gosec
106106 "aws" , "s3api" ,
107107 "head-bucket" ,
108108 "--bucket" , bucket ,
@@ -113,7 +113,7 @@ func awsCmdBucketExists(bucket string) bool {
113113}
114114
115115func awsCmdExists (key string ) bool {
116- if err := exec .Command (
116+ if err := exec .Command ( //nolint:gosec
117117 "aws" , "s3api" ,
118118 "head-object" ,
119119 "--bucket" , testBucket ,
@@ -126,7 +126,7 @@ func awsCmdExists(key string) bool {
126126}
127127
128128func awsCmdPutKey (key string ) {
129- if err := exec .Command (
129+ if err := exec .Command ( //nolint:gosec
130130 "aws" , "s3api" ,
131131 "put-object" ,
132132 "--bucket" , testBucket ,
@@ -140,16 +140,18 @@ func awsCmdPutKey(key string) {
140140func awsCmdPutKeys (keys []string ) {
141141 // create test data
142142 tmpDir , _ := os .MkdirTemp ("" , "" )
143- defer os .RemoveAll (tmpDir )
143+ defer func () {
144+ _ = os .RemoveAll (tmpDir )
145+ }()
144146
145147 for _ , k := range keys {
146148 testDataFilepath := filepath .Join (tmpDir , k )
147- testFile , _ := os .Create (testDataFilepath )
149+ testFile , _ := os .Create (testDataFilepath ) //nolint:gosec
148150 _ , _ = testFile .WriteString (testObjectData )
149- testFile .Close ()
151+ _ = testFile .Close ()
150152 }
151153 // sync to bucket
152- cmd := exec .Command (
154+ cmd := exec .Command ( //nolint:gosec
153155 "aws" , "s3" ,
154156 "sync" , tmpDir , fmt .Sprintf ("s3://%v" , testBucket ),
155157 )
@@ -200,21 +202,21 @@ func awsCmdMeta() awsMeta {
200202}
201203
202204func awsCmdGetTestObject () string {
203- tmpDir , _ := os .MkdirTemp ("" , "" )
204- defer os . RemoveAll ( tmpDir )
205-
206- testDataFilepath := filepath . Join ( tmpDir , "data.txt" )
205+ testFile , _ := os .CreateTemp ("" , "data-*.txt " )
206+ defer func () {
207+ _ = os . Remove ( testFile . Name ())
208+ }( )
207209
208- if err := exec .Command (
210+ if err := exec .Command ( //nolint:gosec
209211 "aws" , "s3api" ,
210212 "get-object" ,
211213 "--bucket" , testBucket ,
212214 "--key" , testObjectKey ,
213- testDataFilepath ).Run (); err != nil {
215+ testFile . Name () ).Run (); err != nil {
214216 panic (err )
215217 }
216218
217- testFileContents , _ := os .ReadFile (testDataFilepath )
219+ testFileContents , _ := os .ReadFile (testFile . Name () )
218220 return string (testFileContents )
219221}
220222
@@ -255,7 +257,8 @@ func TestCreateS3ClientAndReady(t *testing.T) {
255257 // test bad case
256258
257259 // ARRANGE
258- os .Unsetenv ("AWS_REGION" )
260+ err = os .Unsetenv ("AWS_REGION" )
261+ require .Nil (t , err )
259262
260263 // ACTION
261264 client , err = New ()
@@ -279,7 +282,8 @@ func TestCreateS3ClientWithMaxRetries(t *testing.T) {
279282 // test bad case
280283
281284 // ARRANGE
282- os .Unsetenv ("AWS_REGION" )
285+ err = os .Unsetenv ("AWS_REGION" )
286+ require .Nil (t , err )
283287
284288 // ACTION
285289 _ , err = NewWithMaxRetries (2 )
0 commit comments