1
1
import { checkCacheDirectoryPermissions } from "../lib/helpers/cacheDirectoryCheck.ts" ;
2
+ import type { Config } from "../lib/helpers/config.ts" ;
3
+
4
+ function createMockConfig (
5
+ cacheConfig : { enabled : boolean ; directory : string } ,
6
+ ) : Config {
7
+ return {
8
+ server : {
9
+ port : 8282 ,
10
+ host : "127.0.0.1" ,
11
+ use_unix_socket : false ,
12
+ unix_socket_path : "/tmp/invidious-companion.sock" ,
13
+ secret_key : "1234567890123456" ,
14
+ verify_requests : false ,
15
+ encrypt_query_params : false ,
16
+ enable_metrics : false ,
17
+ } ,
18
+ cache : cacheConfig ,
19
+ networking : {
20
+ proxy : null ,
21
+ fetch : {
22
+ timeout_ms : 30000 ,
23
+ retry : {
24
+ enabled : false ,
25
+ times : 1 ,
26
+ initial_debounce : 0 ,
27
+ max_debounce : 0 ,
28
+ backoff_multiplier : 0 ,
29
+ } ,
30
+ } ,
31
+ videoplayback : {
32
+ ump : false ,
33
+ video_fetch_chunk_size_mb : 5 ,
34
+ } ,
35
+ } ,
36
+ jobs : {
37
+ youtube_session : {
38
+ po_token_enabled : false ,
39
+ frequency : "*/5 * * * *" ,
40
+ } ,
41
+ } ,
42
+ youtube_session : {
43
+ oauth_enabled : false ,
44
+ cookies : "" ,
45
+ } ,
46
+ } ;
47
+ }
2
48
3
49
Deno . test ( {
4
50
name : "Cache directory permissions check - disabled cache" ,
5
51
fn ( ) {
6
- const config = {
7
- cache : {
8
- enabled : false ,
9
- directory : "/nonexistent/path" ,
10
- } ,
11
- } ;
52
+ const config = createMockConfig ( {
53
+ enabled : false ,
54
+ directory : "/nonexistent/path" ,
55
+ } ) ;
12
56
13
57
// Should not throw when cache is disabled
14
58
checkCacheDirectoryPermissions ( config ) ;
@@ -18,12 +62,10 @@ Deno.test({
18
62
Deno . test ( {
19
63
name : "Cache directory permissions check - valid directory" ,
20
64
fn ( ) {
21
- const config = {
22
- cache : {
23
- enabled : true ,
24
- directory : "/tmp" ,
25
- } ,
26
- } ;
65
+ const config = createMockConfig ( {
66
+ enabled : true ,
67
+ directory : "/tmp" ,
68
+ } ) ;
27
69
28
70
// Should not throw for /tmp which should be writable
29
71
checkCacheDirectoryPermissions ( config ) ;
@@ -33,25 +75,26 @@ Deno.test({
33
75
Deno . test ( {
34
76
name : "Cache directory permissions check - nonexistent parent directory" ,
35
77
fn ( ) {
36
- const config = {
37
- cache : {
38
- enabled : true ,
39
- directory : "/nonexistent/path" ,
40
- } ,
41
- } ;
78
+ const config = createMockConfig ( {
79
+ enabled : true ,
80
+ directory : "/nonexistent/path" ,
81
+ } ) ;
42
82
43
83
// Should throw for nonexistent parent directory
44
84
try {
45
85
checkCacheDirectoryPermissions ( config ) ;
46
86
throw new Error ( "Expected function to throw" ) ;
47
87
} catch ( err ) {
48
- if ( err . message . includes ( "Expected function to throw" ) ) {
88
+ const errorMessage = err instanceof Error
89
+ ? err . message
90
+ : String ( err ) ;
91
+ if ( errorMessage . includes ( "Expected function to throw" ) ) {
49
92
throw err ;
50
93
}
51
94
// Expected error - check it contains helpful information
52
- if ( ! err . message . includes ( "does not exist" ) ) {
95
+ if ( ! errorMessage . includes ( "does not exist" ) ) {
53
96
throw new Error (
54
- `Expected error message to mention directory doesn't exist, got: ${ err . message } ` ,
97
+ `Expected error message to mention directory doesn't exist, got: ${ errorMessage } ` ,
55
98
) ;
56
99
}
57
100
}
0 commit comments