@@ -94,48 +94,68 @@ t.test('wrong libc with overridden libc', async t =>
94
94
} ) , { code : 'EBADPLATFORM' } ) )
95
95
96
96
t . test ( 'libc' , ( t ) => {
97
- let PLATFORM = ''
98
-
99
- const _processPlatform = Object . getOwnPropertyDescriptor ( process , 'platform' )
100
- Object . defineProperty ( process , 'platform' , {
101
- enumerable : true ,
102
- configurable : true ,
103
- get : ( ) => PLATFORM ,
104
- } )
105
-
97
+ let noCacheChckPtfm
98
+ let PLATFORM = 'linux'
106
99
let REPORT = { }
107
- const _processReport = process . report . getReport
108
- process . report . getReport = ( ) => REPORT
109
-
110
- t . teardown ( ( ) => {
111
- Object . defineProperty ( process , 'platform' , _processPlatform )
112
- process . report . getReport = _processReport
113
- } )
100
+ let readFileSync
101
+
102
+ function withoutLibcCache ( ) {
103
+ readFileSync = ( ) => {
104
+ throw new Error ( 'File not found' )
105
+ }
106
+ noCacheChckPtfm = ( ...args ) => {
107
+ const original = t . mock ( '..' , {
108
+ '../lib/current-env' : t . mock ( '../lib/current-env' , {
109
+ 'node:fs' : {
110
+ readFileSync,
111
+ } ,
112
+ 'node:process' : {
113
+ platform : PLATFORM ,
114
+ report : {
115
+ getReport : ( ) => REPORT ,
116
+ } ,
117
+ } ,
118
+ } ) ,
119
+ } ) . checkPlatform
120
+ withoutLibcCache ( )
121
+ return original ( ...args )
122
+ }
123
+ }
124
+
125
+ withoutLibcCache ( )
114
126
115
127
t . test ( 'fails when not in linux' , ( t ) => {
116
128
PLATFORM = 'darwin'
117
129
118
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
130
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
119
131
'fails for glibc when not in linux' )
120
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
132
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
121
133
'fails for musl when not in linux' )
122
134
t . end ( )
123
135
} )
124
136
125
137
t . test ( 'glibc' , ( t ) => {
126
138
PLATFORM = 'linux'
127
139
140
+ readFileSync = ( ) => 'this ldd file contains GNU C Library'
141
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc from ldd file' )
142
+
128
143
REPORT = { }
129
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
144
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
130
145
'fails when report is missing header property' )
131
146
132
147
REPORT = { header : { } }
133
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
148
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
134
149
'fails when header is missing glibcVersionRuntime property' )
135
150
136
151
REPORT = { header : { glibcVersionRuntime : '1' } }
137
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
138
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
152
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
153
+
154
+ readFileSync = ( ) => 'this ldd file is unsupported'
155
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
156
+ 'fails when ldd file exists but is not something known' )
157
+
158
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
139
159
'does not allow musl on glibc' )
140
160
141
161
t . end ( )
@@ -144,25 +164,28 @@ t.test('libc', (t) => {
144
164
t . test ( 'musl' , ( t ) => {
145
165
PLATFORM = 'linux'
146
166
167
+ readFileSync = ( ) => 'this ldd file contains musl'
168
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl from ldd file' )
169
+
147
170
REPORT = { }
148
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
171
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
149
172
'fails when report is missing sharedObjects property' )
150
173
151
174
REPORT = { sharedObjects : { } }
152
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
175
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
153
176
'fails when sharedObjects property is not an array' )
154
177
155
178
REPORT = { sharedObjects : [ ] }
156
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
179
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
157
180
'fails when sharedObjects does not contain musl' )
158
181
159
182
REPORT = { sharedObjects : [ 'ld-musl-foo' ] }
160
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as ld-musl-' )
183
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl as ld-musl-' )
161
184
162
185
REPORT = { sharedObjects : [ 'libc.musl-' ] }
163
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as libc.musl-' )
186
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl as libc.musl-' )
164
187
165
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
188
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
166
189
'does not allow glibc on musl' )
167
190
168
191
t . end ( )
0 commit comments