@@ -50,6 +50,7 @@ enum ServerType {
50
50
pub struct RedisServer {
51
51
pub process : process:: Child ,
52
52
stunnel_process : Option < process:: Child > ,
53
+ tempdir : Option < tempdir:: TempDir > ,
53
54
addr : redis:: ConnectionAddr ,
54
55
}
55
56
@@ -115,6 +116,7 @@ impl RedisServer {
115
116
redis_cmd
116
117
. stdout ( process:: Stdio :: null ( ) )
117
118
. stderr ( process:: Stdio :: null ( ) ) ;
119
+ let tempdir = tempdir:: TempDir :: new ( "redis" ) . expect ( "failed to create tempdir" ) ;
118
120
match addr {
119
121
redis:: ConnectionAddr :: Tcp ( ref bind, server_port) => {
120
122
redis_cmd
@@ -126,6 +128,7 @@ impl RedisServer {
126
128
RedisServer {
127
129
process : spawner ( & mut redis_cmd) ,
128
130
stunnel_process : None ,
131
+ tempdir : None ,
129
132
addr,
130
133
}
131
134
}
@@ -135,43 +138,42 @@ impl RedisServer {
135
138
. arg ( "--port" )
136
139
. arg ( "0" )
137
140
. arg ( "--unixsocket" )
138
- . arg ( & format ! ( "/tmp/ redis-rs-test-{} .sock", port ) ) ;
141
+ . arg ( tempdir . path ( ) . join ( " redis.sock") ) ;
139
142
140
143
// create a self-signed TLS server cert
141
144
process:: Command :: new ( "openssl" )
142
- . args ( & [
143
- "req" ,
144
- "-nodes" ,
145
- "-new" ,
146
- "-x509" ,
147
- "-keyout" ,
148
- & format ! ( "/tmp/redis-rs-test-{}.pem" , port) ,
149
- "-out" ,
150
- & format ! ( "/tmp/redis-rs-test-{}.crt" , port) ,
151
- "-subj" ,
152
- "/C=XX/ST=crates/L=redis-rs/O=testing/CN=localhost" ,
153
- ] )
145
+ . arg ( "req" )
146
+ . arg ( "-nodes" )
147
+ . arg ( "-new" )
148
+ . arg ( "-x509" )
149
+ . arg ( "-keyout" )
150
+ . arg ( tempdir. path ( ) . join ( "key.pem" ) )
151
+ . arg ( "-out" )
152
+ . arg ( tempdir. path ( ) . join ( "cert.crt" ) )
153
+ . arg ( "-subj" )
154
+ . arg ( "/C=XX/ST=crates/L=redis-rs/O=testing/CN=localhost" )
154
155
. stdout ( process:: Stdio :: null ( ) )
155
156
. stderr ( process:: Stdio :: null ( ) )
156
157
. spawn ( )
157
158
. expect ( "failed to spawn openssl" )
158
159
. wait ( )
159
160
. expect ( "failed to create self-signed TLS certificate" ) ;
160
161
161
- let stunnel_config_path = format ! ( "/tmp/redis-rs- stunnel-{} .conf", port ) ;
162
+ let stunnel_config_path = tempdir . path ( ) . join ( " stunnel.conf") ;
162
163
let mut stunnel_config_file = fs:: File :: create ( & stunnel_config_path) . unwrap ( ) ;
163
164
stunnel_config_file
164
165
. write_all (
165
166
format ! (
166
167
r#"
167
- cert = /tmp/redis-rs-test-{stunnel_port} .crt
168
- key = /tmp/redis-rs-test-{stunnel_port} .pem
168
+ cert = {tempdir}/cert .crt
169
+ key = {tempdir}/key .pem
169
170
verify = 0
170
171
foreground = yes
171
172
[redis]
172
173
accept = {host}:{stunnel_port}
173
- connect = /tmp/redis-rs-test-{stunnel_port} .sock
174
+ connect = {tempdir}/redis .sock
174
175
"# ,
176
+ tempdir = tempdir. path( ) . display( ) ,
175
177
host = host,
176
178
stunnel_port = port,
177
179
)
@@ -193,6 +195,7 @@ impl RedisServer {
193
195
RedisServer {
194
196
process : spawner ( & mut redis_cmd) ,
195
197
stunnel_process : Some ( stunnel_cmd. spawn ( ) . expect ( "could not start stunnel" ) ) ,
198
+ tempdir : Some ( tempdir) ,
196
199
addr,
197
200
}
198
201
}
@@ -205,6 +208,7 @@ impl RedisServer {
205
208
RedisServer {
206
209
process : spawner ( & mut redis_cmd) ,
207
210
stunnel_process : None ,
211
+ tempdir : Some ( tempdir) ,
208
212
addr,
209
213
}
210
214
}
0 commit comments