@@ -9,13 +9,15 @@ import (
99 "time"
1010
1111 "github.com/PowerDNS/simpleblob/backends/s3"
12- "github.com/PowerDNS/simpleblob/backends/s3/s3testing"
1312 "github.com/PowerDNS/simpleblob/tester"
1413 "github.com/minio/minio-go/v7"
1514 "github.com/minio/minio-go/v7/pkg/credentials"
15+ "github.com/testcontainers/testcontainers-go"
16+ testcontainersminio "github.com/testcontainers/testcontainers-go/modules/minio"
1617)
1718
1819func TestFileSecretsCredentials (t * testing.T ) {
20+ testcontainers .SkipIfProviderIsNotHealthy (t )
1921 tempDir := t .TempDir ()
2022
2123 access , secret := secretsPaths (tempDir )
@@ -30,15 +32,20 @@ func TestFileSecretsCredentials(t *testing.T) {
3032 ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
3133 defer cancel ()
3234
33- // Create server
34- addr , stop , err := s3testing .ServeMinio (ctx , tempDir )
35- if errors .Is (err , s3testing .ErrMinioNotFound ) {
36- t .Skip ("minio binary not found locally, make sure it is in PATH" )
35+ container , err := testcontainersminio .Run (ctx , "quay.io/minio/minio" )
36+ if err != nil {
37+ t .Fatal (err )
3738 }
39+ defer func () {
40+ if err := container .Terminate (ctx ); err != nil {
41+ t .Log (err )
42+ }
43+ }()
44+
45+ addr , err := container .ConnectionString (ctx )
3846 if err != nil {
3947 t .Fatal (err )
4048 }
41- defer func () { _ = stop () }()
4249
4350 // Create minio client, using our provider.
4451 creds := credentials .New (provider )
@@ -65,7 +72,7 @@ func TestFileSecretsCredentials(t *testing.T) {
6572 // First credential files creation.
6673 // Keep them empty for now,
6774 // so that calls to the server will fail.
68- writeSecrets (t , tempDir , "" )
75+ writeSecrets (t , tempDir , "" , "" )
6976
7077 // The files do not hold the right values,
7178 // so a call to the server should fail.
@@ -74,31 +81,38 @@ func TestFileSecretsCredentials(t *testing.T) {
7481 // Write the right keys to the files.
7582 // We're not testing expiry here,
7683 // and forcing credentials cache to update.
77- writeSecrets (t , tempDir , s3testing . AdminUserOrPassword )
84+ writeSecrets (t , tempDir , container . Username , container . Password )
7885 creds .Expire ()
7986 assertClientSuccess (true , "after changing files content" )
8087
8188 // Change content of the files.
82- writeSecrets (t , tempDir , "badcredentials " )
89+ writeSecrets (t , tempDir , "bad-user" , "bad-password " )
8390 creds .Expire ()
8491 assertClientSuccess (false , "after changing again, to bad credentials" )
8592}
8693
8794func TestBackendWithSecrets (t * testing.T ) {
95+ testcontainers .SkipIfProviderIsNotHealthy (t )
8896 tempDir := t .TempDir ()
8997
9098 ctx := context .Background ()
9199 ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
92100 defer cancel ()
93101
94- addr , stop , err := s3testing . ServeMinio (ctx , tempDir )
95- if errors . Is ( err , s3testing . ErrMinioNotFound ) {
96- t .Skip ( "minio binary not found locally, make sure it is in PATH" )
102+ container , err := testcontainersminio . Run (ctx , "quay.io/minio/minio" )
103+ if err != nil {
104+ t .Fatal ( err )
97105 }
106+ defer func () {
107+ if err := container .Terminate (ctx ); err != nil {
108+ t .Log (err )
109+ }
110+ }()
111+
112+ addr , err := container .ConnectionString (ctx )
98113 if err != nil {
99114 t .Fatal (err )
100115 }
101- defer func () { _ = stop () }()
102116
103117 // Prepare backend options to reuse.
104118 // These will not change.
@@ -119,15 +133,15 @@ func TestBackendWithSecrets(t *testing.T) {
119133 }
120134
121135 // Now write files, but with bad content.
122- writeSecrets (t , tempDir , "" )
136+ writeSecrets (t , tempDir , "" , "" )
123137 _ , err = s3 .New (ctx , opt )
124138 if err == nil || err .Error () != "Access Denied." {
125139 t .Fatal ("backend should not start with bad credentials" )
126140 }
127141
128142 // Write the good content.
129143 // Now the backend should start and be able to perform a request.
130- writeSecrets (t , tempDir , s3testing . AdminUserOrPassword )
144+ writeSecrets (t , tempDir , container . Username , container . Password )
131145
132146 backend , err := s3 .New (ctx , opt )
133147 if err != nil {
@@ -153,14 +167,13 @@ func secretsPaths(dir string) (access, secret string) {
153167
154168// writeSecrets writes content to files called "access-key" and "secret-key"
155169// in dir.
156- // It returns
157- func writeSecrets (t testing.TB , dir , content string ) {
170+ func writeSecrets (t testing.TB , dir , adminUser , password string ) {
158171 access , secret := secretsPaths (dir )
159- err := os .WriteFile (access , []byte (content ), 0666 )
172+ err := os .WriteFile (access , []byte (adminUser ), 0666 )
160173 if err != nil {
161174 t .Fatal (err )
162175 }
163- err = os .WriteFile (secret , []byte (content ), 0666 )
176+ err = os .WriteFile (secret , []byte (password ), 0666 )
164177 if err != nil {
165178 t .Fatal (err )
166179 }
0 commit comments