@@ -3,6 +3,8 @@ package s3provider
33import (
44 "context"
55 "fmt"
6+ "io"
7+ "net/http"
68 "testing"
79
810 "github.com/google/go-cmp/cmp"
@@ -27,17 +29,19 @@ func TestNew(t *testing.T) {
2729
2830 // Test Output
2931 output := s3provider .Output ()
30- require .True (t ,
31- cmp .Equal (& Output {
32- AccessKey : accessKey ,
33- SecretKey : secretKey ,
34- Bucket : DefaultBucket ,
35- ConsoleURL : s3provider .GetConsoleURL (),
36- Endpoint : s3provider .GetEndpoint (),
37- BaseEndpoint : fmt .Sprintf ("%s:%d" , DefaultHost , port ),
38- Region : s3provider .GetRegion (),
39- UseCache : false ,
40- }, output ))
32+ expected := & Output {
33+ AccessKey : accessKey ,
34+ SecretKey : secretKey ,
35+ Bucket : DefaultBucket ,
36+ ConsoleURL : s3provider .GetConsoleURL (),
37+ ConsoleBaseURL : s3provider .GetConsoleBaseURL (),
38+ Endpoint : s3provider .GetEndpoint (),
39+ BaseEndpoint : fmt .Sprintf ("%s:%d" , DefaultHost , port ),
40+ Region : s3provider .GetRegion (),
41+ UseCache : false ,
42+ }
43+ fmt .Printf ("%#v\n %#v\n " , expected , output )
44+ require .True (t , cmp .Equal (expected , output ))
4145 require .Len (t , output .AccessKey , accessKeyLength )
4246 require .Len (t , output .SecretKey , secretKeyLength )
4347
@@ -48,7 +52,20 @@ func TestNew(t *testing.T) {
4852 })
4953 require .NoError (t , err )
5054
51- helperUploadFile (t , minioClient , s3provider .GetBucket ())
55+ info , err := helperUploadFile (minioClient , s3provider .GetBucket ())
56+ require .NoError (t , err )
57+ require .Equal (t , int64 (7 ), info .Size )
58+
59+ statusCode , err := helperDownloadFile (
60+ fmt .Sprintf (
61+ "http://%s/%s/%s" ,
62+ output .Endpoint ,
63+ output .Bucket ,
64+ info .Key ,
65+ ),
66+ )
67+ require .NoError (t , err )
68+ require .Equal (t , http .StatusOK , statusCode )
5269}
5370
5471func TestNewFrom (t * testing.T ) {
@@ -64,16 +81,17 @@ func TestNewFrom(t *testing.T) {
6481 require .NoError (t , err )
6582
6683 // Test Output
67- fmt .Printf ("%#v\n " , output )
68- require .True (t ,
69- cmp .Equal (& Output {
70- Bucket : DefaultBucket ,
71- ConsoleURL : fmt .Sprintf ("http://%s:%d" , "127.0.0.1" , consolePort ),
72- Endpoint : fmt .Sprintf ("%s:%d" , "127.0.0.1" , port ),
73- BaseEndpoint : fmt .Sprintf ("%s:%d" , "minio" , port ),
74- Region : DefaultRegion ,
75- UseCache : false ,
76- }, output , cmpopts .IgnoreFields (Output {}, "AccessKey" , "SecretKey" )))
84+ expected := & Output {
85+ Bucket : DefaultBucket ,
86+ ConsoleURL : fmt .Sprintf ("http://%s:%d" , "127.0.0.1" , consolePort ),
87+ ConsoleBaseURL : fmt .Sprintf ("http://%s:%d" , DefaultHost , consolePort ),
88+ Endpoint : fmt .Sprintf ("%s:%d" , "127.0.0.1" , port ),
89+ BaseEndpoint : fmt .Sprintf ("%s:%d" , DefaultHost , port ),
90+ Region : DefaultRegion ,
91+ UseCache : false ,
92+ }
93+ fmt .Printf ("%#v\n %#v\n " , expected , output )
94+ require .True (t , cmp .Equal (expected , output , cmpopts .IgnoreFields (Output {}, "AccessKey" , "SecretKey" )))
7795 require .Len (t , output .AccessKey , accessKeyLength )
7896 require .Len (t , output .SecretKey , secretKeyLength )
7997
@@ -84,10 +102,23 @@ func TestNewFrom(t *testing.T) {
84102 })
85103 require .NoError (t , err )
86104
87- helperUploadFile (t , minioClient , output .Bucket )
105+ info , err := helperUploadFile (minioClient , output .Bucket )
106+ require .NoError (t , err )
107+ require .Equal (t , int64 (7 ), info .Size )
108+
109+ statusCode , err := helperDownloadFile (
110+ fmt .Sprintf (
111+ "http://%s/%s/%s" ,
112+ output .Endpoint ,
113+ output .Bucket ,
114+ info .Key ,
115+ ),
116+ )
117+ require .NoError (t , err )
118+ require .Equal (t , http .StatusOK , statusCode )
88119}
89120
90- func helperUploadFile (t * testing. T , minioClient * minio.Client , bucket string ) {
121+ func helperUploadFile (minioClient * minio.Client , bucket string ) ( * minio. UploadInfo , error ) {
91122 // Test file upload
92123 filename := "test.txt"
93124 filePath := "./" + filename
@@ -99,6 +130,23 @@ func helperUploadFile(t *testing.T, minioClient *minio.Client, bucket string) {
99130 filePath ,
100131 minio.PutObjectOptions {ContentType : contentType },
101132 )
102- require .NoError (t , err )
103- require .Equal (t , int64 (7 ), info .Size )
133+ if err != nil {
134+ return nil , err
135+ }
136+ return & info , nil
137+ }
138+
139+ func helperDownloadFile (url string ) (int , error ) {
140+ fmt .Printf ("Downloading: %s\n " , url )
141+ resp , err := http .Get (url ) //nolint:gosec //ignoring G107
142+ if err != nil {
143+ return 0 , err
144+ }
145+ defer func (Body io.ReadCloser ) {
146+ err := Body .Close ()
147+ if err != nil {
148+ panic (err )
149+ }
150+ }(resp .Body )
151+ return resp .StatusCode , nil
104152}
0 commit comments