File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed
src/subsystems/IO/Storage.service/connectors Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export class LocalStorage extends StorageConnector {
4949 private findStorageFolder ( folder ) {
5050 let _storageFolder = folder ;
5151
52- if ( fs . existsSync ( _storageFolder ) ) {
52+ if ( _storageFolder && fs . existsSync ( _storageFolder ) ) {
5353 return _storageFolder ;
5454 }
5555
Original file line number Diff line number Diff line change 1+ import { LocalStorage } from '@sre/IO/Storage.service/connectors/LocalStorage.class' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ describe ( 'LocalStorage Tests' , ( ) => {
5+ it ( 'should initialize with undefined folder without crashing' , ( ) => {
6+ // Test with undefined settings
7+ expect ( ( ) => {
8+ new LocalStorage ( ) ;
9+ } ) . not . toThrow ( ) ;
10+
11+ // Test with empty settings object
12+ expect ( ( ) => {
13+ new LocalStorage ( { } ) ;
14+ } ) . not . toThrow ( ) ;
15+
16+ // Test with explicitly undefined folder
17+ expect ( ( ) => {
18+ new LocalStorage ( { folder : undefined } ) ;
19+ } ) . not . toThrow ( ) ;
20+ } ) ;
21+
22+ it ( 'should initialize with valid folder path' , ( ) => {
23+ const tempDir = require ( 'os' ) . tmpdir ( ) ;
24+
25+ expect ( ( ) => {
26+ new LocalStorage ( { folder : tempDir } ) ;
27+ } ) . not . toThrow ( ) ;
28+ } ) ;
29+
30+ it ( 'should handle non-existent folder gracefully' , ( ) => {
31+ // This should not crash but may log warnings as designed
32+ expect ( ( ) => {
33+ new LocalStorage ( { folder : '/non/existent/path/that/should/not/exist' } ) ;
34+ } ) . not . toThrow ( ) ;
35+ } ) ;
36+ } ) ;
Original file line number Diff line number Diff line change @@ -119,11 +119,10 @@ export class StorageInstance extends SDKObject {
119119 * @param resourceName - The name or smythfs:// uri of the resource to check
120120 * @returns true if the resource exists, false otherwise
121121 */
122- async exists ( resourceName : string ) {
122+ async exists ( resourceName : string ) : Promise < boolean > {
123123 const uri = resourceName . startsWith ( 'smythfs://' ) ? resourceName : await this . getResourceUri ( resourceName ) ;
124124 try {
125- await this . fs . exists ( uri , this . _candidate ) ;
126- return uri ;
125+ return await this . fs . exists ( uri , this . _candidate ) ;
127126 } catch ( error ) {
128127 console . error ( error ) ;
129128 throw error ;
You can’t perform that action at this time.
0 commit comments