@@ -11,41 +11,30 @@ import (
1111)
1212
1313func TestNew_NilConfig (t * testing.T ) {
14- fs , err := New (nil , nil , nil )
14+ fs := New (nil )
1515
16- require .Error (t , err )
17- assert .Nil (t , fs )
18- assert .ErrorIs (t , err , errInvalidConfig )
16+ require .NotNil (t , fs )
17+ assert .Equal (t , "ftp://unconfigured" , fs .(* fileSystem ).CommonFileSystem .Location )
1918}
2019
2120func TestNew_EmptyHost (t * testing.T ) {
2221 config := & Config {Host : "" , Port : 2121 }
2322
24- fs , err := New (config , nil , nil )
25-
26- require .Error (t , err )
27- assert .Nil (t , fs )
28- assert .ErrorIs (t , err , errInvalidConfig )
29- }
30-
31- func TestNew_InvalidPort_Negative (t * testing.T ) {
32- config := & Config {Host : "localhost" , Port : - 1 }
23+ fs := New (config )
3324
34- fs , err := New ( config , nil , nil )
25+ require . NotNil ( t , fs )
3526
36- require .Error (t , err )
37- assert .Nil (t , fs )
38- assert .ErrorIs (t , err , errInvalidConfig )
27+ assert .Equal (t , "ftp://unconfigured" , fs .(* fileSystem ).CommonFileSystem .Location )
3928}
4029
4130func TestNew_PortZero (t * testing.T ) {
4231 config := & Config {Host : "localhost" , Port : 0 }
4332
44- fs , err := New (config , nil , nil )
33+ fs := New (config )
4534
46- require .Error (t , err )
47- assert . Nil ( t , fs )
48- assert .ErrorIs (t , err , errInvalidConfig )
35+ require .NotNil (t , fs )
36+ // Port 0 will default to 21 in buildLocation
37+ assert .Equal (t , "localhost:21" , fs .( * fileSystem ). CommonFileSystem . Location )
4938}
5039
5140func TestNew_ConnectionFailure_StartsRetry (t * testing.T ) {
@@ -62,6 +51,13 @@ func TestNew_ConnectionFailure_StartsRetry(t *testing.T) {
6251 Password : "testpass" ,
6352 }
6453
54+ fs := New (config )
55+ require .NotNil (t , fs )
56+
57+ // Inject logger and metrics (mimicking AddFileStore behavior)
58+ fs .UseLogger (mockLogger )
59+ fs .UseMetrics (mockMetrics )
60+
6561 mockLogger .EXPECT ().Warnf (
6662 "FTP server %s not available, starting background retry: %v" ,
6763 gomock .Any (),
@@ -72,10 +68,7 @@ func TestNew_ConnectionFailure_StartsRetry(t *testing.T) {
7268 mockLogger .EXPECT ().Debug (gomock .Any ()).AnyTimes ()
7369 mockMetrics .EXPECT ().RecordHistogram (gomock .Any (), file .AppFileStats , gomock .Any (), gomock .Any ()).AnyTimes ()
7470
75- fs , err := New (config , mockLogger , mockMetrics )
76-
77- require .NoError (t , err )
78- require .NotNil (t , fs )
71+ fs .Connect ()
7972
8073 time .Sleep (100 * time .Millisecond )
8174
@@ -96,6 +89,15 @@ func TestNew_Success(t *testing.T) {
9689 Password : "testpass" ,
9790 }
9891
92+ fs := New (config )
93+ require .NotNil (t , fs )
94+
95+ assert .Equal (t , "localhost:2121" , fs .(* fileSystem ).CommonFileSystem .Location )
96+
97+ // Inject logger and metrics
98+ fs .UseLogger (mockLogger )
99+ fs .UseMetrics (mockMetrics )
100+
99101 mockMetrics .EXPECT ().NewHistogram (file .AppFileStats , gomock .Any (), gomock .Any ())
100102
101103 mockLogger .EXPECT ().Infof ("connected to %s" , "localhost:2121" ).MaxTimes (1 )
@@ -108,12 +110,7 @@ func TestNew_Success(t *testing.T) {
108110 mockLogger .EXPECT ().Debug (gomock .Any ()).AnyTimes ()
109111 mockMetrics .EXPECT ().RecordHistogram (gomock .Any (), file .AppFileStats , gomock .Any (), gomock .Any ()).AnyTimes ()
110112
111- fs , err := New (config , mockLogger , mockMetrics )
112-
113- require .NoError (t , err )
114- require .NotNil (t , fs )
115-
116- assert .Equal (t , "localhost:2121" , fs .(* fileSystem ).CommonFileSystem .Location )
113+ fs .Connect ()
117114}
118115
119116func TestNew_WithRemoteDir (t * testing.T ) {
@@ -131,6 +128,16 @@ func TestNew_WithRemoteDir(t *testing.T) {
131128 RemoteDir : "/uploads" ,
132129 }
133130
131+ fs := New (config )
132+
133+ require .NotNil (t , fs )
134+
135+ assert .Equal (t , "localhost:2121/uploads" , fs .(* fileSystem ).CommonFileSystem .Location )
136+
137+ // Inject logger and metrics
138+ fs .UseLogger (mockLogger )
139+ fs .UseMetrics (mockMetrics )
140+
134141 mockMetrics .EXPECT ().NewHistogram (file .AppFileStats , gomock .Any (), gomock .Any ())
135142
136143 mockLogger .EXPECT ().Infof ("connected to %s" , "localhost:2121/uploads" ).MaxTimes (1 )
@@ -143,12 +150,7 @@ func TestNew_WithRemoteDir(t *testing.T) {
143150 mockLogger .EXPECT ().Debug (gomock .Any ()).AnyTimes ()
144151 mockMetrics .EXPECT ().RecordHistogram (gomock .Any (), file .AppFileStats , gomock .Any (), gomock .Any ()).AnyTimes ()
145152
146- fs , err := New (config , mockLogger , mockMetrics )
147-
148- require .NoError (t , err )
149- require .NotNil (t , fs )
150-
151- assert .Equal (t , "localhost:2121/uploads" , fs .(* fileSystem ).CommonFileSystem .Location )
153+ fs .Connect ()
152154}
153155
154156func TestNew_WithRootRemoteDir (t * testing.T ) {
@@ -166,6 +168,15 @@ func TestNew_WithRootRemoteDir(t *testing.T) {
166168 RemoteDir : "/" ,
167169 }
168170
171+ fs := New (config )
172+ require .NotNil (t , fs )
173+
174+ assert .Equal (t , "localhost:2121" , fs .(* fileSystem ).CommonFileSystem .Location )
175+
176+ // Inject logger and metrics
177+ fs .UseLogger (mockLogger )
178+ fs .UseMetrics (mockMetrics )
179+
169180 mockMetrics .EXPECT ().NewHistogram (file .AppFileStats , gomock .Any (), gomock .Any ())
170181
171182 mockLogger .EXPECT ().Infof ("connected to %s" , "localhost:2121" ).MaxTimes (1 )
@@ -178,21 +189,13 @@ func TestNew_WithRootRemoteDir(t *testing.T) {
178189 mockLogger .EXPECT ().Debug (gomock .Any ()).AnyTimes ()
179190 mockMetrics .EXPECT ().RecordHistogram (gomock .Any (), file .AppFileStats , gomock .Any (), gomock .Any ()).AnyTimes ()
180191
181- fs , err := New (config , mockLogger , mockMetrics )
182-
183- require .NoError (t , err )
184- require .NotNil (t , fs )
185-
186- assert .Equal (t , "localhost:2121" , fs .(* fileSystem ).CommonFileSystem .Location )
192+ fs .Connect ()
187193}
188194
189195func TestNew_WithCustomDialTimeout (t * testing.T ) {
190196 ctrl := gomock .NewController (t )
191197 defer ctrl .Finish ()
192198
193- mockLogger := file .NewMockLogger (ctrl )
194- mockMetrics := file .NewMockMetrics (ctrl )
195-
196199 config := & Config {
197200 Host : "localhost" ,
198201 Port : 2121 ,
@@ -201,22 +204,12 @@ func TestNew_WithCustomDialTimeout(t *testing.T) {
201204 DialTimeout : 3 * time .Second ,
202205 }
203206
204- mockMetrics .EXPECT ().NewHistogram (file .AppFileStats , gomock .Any (), gomock .Any ())
205-
206- mockLogger .EXPECT ().Infof ("connected to %s" , "localhost:2121" ).MaxTimes (1 )
207- mockLogger .EXPECT ().Warnf (
208- "FTP server %s not available, starting background retry: %v" ,
209- gomock .Any (),
210- gomock .Any (),
211- ).MaxTimes (1 )
212-
213- mockLogger .EXPECT ().Debug (gomock .Any ()).AnyTimes ()
214- mockMetrics .EXPECT ().RecordHistogram (gomock .Any (), file .AppFileStats , gomock .Any (), gomock .Any ()).AnyTimes ()
215-
216- fs , err := New (config , mockLogger , mockMetrics )
207+ fs := New (config )
217208
218- require .NoError (t , err )
219209 require .NotNil (t , fs )
210+
211+ adapter := fs .(* fileSystem ).CommonFileSystem .Provider .(* storageAdapter )
212+ assert .Equal (t , 3 * time .Second , adapter .cfg .DialTimeout )
220213}
221214
222215func TestConnect_AlreadyConnected (t * testing.T ) {
0 commit comments