11import { test } from 'tape'
22import { run , asAdmin } from '../test.js'
33import { readdirSync } from 'node:fs'
4+ import { readFile } from 'node:fs/promises'
5+ import path from 'node:path'
46
57const testCollectionName = 'get-test'
68const testCollection = '/db/' + testCollectionName
@@ -34,7 +36,8 @@ const expectedDirectoryListing = [
3436 'empty-subcollection' ,
3537 'index.html' ,
3638 'subcollection' ,
37- 'test.xq'
39+ 'test.xq' ,
40+ 'xincludes.xml'
3841]
3942
4043async function prepare ( t ) {
@@ -52,7 +55,14 @@ async function prepare (t) {
5255 storeResourceQuery ( testCollection , 'a20.txt' , '"test"' ) ,
5356 storeResourceQuery ( testCollection , 'a22.xml' , '<test />' ) ,
5457 storeResourceQuery ( testCollection , 'index.html' , '<html><body>1</body></html>' ) ,
55- storeResourceQuery ( testCollection , 'test.xq' , '"1"' )
58+ storeResourceQuery ( testCollection , 'test.xq' , '"1"' ) ,
59+ storeResourceQuery (
60+ testCollection ,
61+ 'xincludes.xml' ,
62+ `<xml xmlns:xi="http://www.w3.org/2001/XInclude">
63+ <xi:include href="./a22.xml"><xi:fallback><p>I am an x include</p></xi:fallback></xi:include>
64+ </xml>`
65+ )
5666 ] . join ( ',' )
5767 const { stderr, stdout } = await run ( 'xst' , [ 'run' , query ] , asAdmin )
5868 if ( stderr ) {
@@ -93,6 +103,43 @@ test('with test collection', async (t) => {
93103 await removeLocalDownload ( )
94104 } )
95105
106+ t . test ( `can get ${ testCollection } as admin without expanding xincludes` , async ( st ) => {
107+ const { stderr, stdout } = await run ( 'xst' , [ 'get' , testCollection , '.' , '--expand-xincludes=no' ] , asAdmin )
108+ if ( stderr ) {
109+ return st . fail ( stderr )
110+ }
111+ st . plan ( 4 )
112+
113+ st . notOk ( stdout , 'no output' )
114+ st . deepEqual ( readdirSync ( testCollectionName ) , expectedDirectoryListing , 'all files were downloaded' )
115+ st . deepEqual ( readdirSync ( testCollectionName + '/subcollection' ) , [ 'b' ] , 'subcollection contents were downloaded' )
116+
117+ const contents = await readFile ( path . join ( testCollectionName , 'xincludes.xml' ) , 'utf-8' )
118+ st . strictEqual (
119+ contents ,
120+ '<xml xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include href="./a22.xml"><xi:fallback><p>I am an x include</p></xi:fallback></xi:include></xml>'
121+ )
122+
123+ await removeLocalDownload ( )
124+ } )
125+
126+ t . test ( `can get ${ testCollection } as admin with expanding xincludes` , async ( st ) => {
127+ const { stderr, stdout } = await run ( 'xst' , [ 'get' , testCollection , '.' , '--expand-xincludes' , 'yes' ] , asAdmin )
128+ if ( stderr ) {
129+ return st . fail ( stderr )
130+ }
131+ st . plan ( 4 )
132+
133+ st . notOk ( stdout , 'no output' )
134+ st . deepEqual ( readdirSync ( testCollectionName ) , expectedDirectoryListing , 'all files were downloaded' )
135+ st . deepEqual ( readdirSync ( testCollectionName + '/subcollection' ) , [ 'b' ] , 'subcollection contents were downloaded' )
136+
137+ const contents = await readFile ( path . join ( testCollectionName , 'xincludes.xml' ) , 'utf-8' )
138+ st . strictEqual ( contents , '<xml xmlns:xi="http://www.w3.org/2001/XInclude"><test/></xml>' )
139+
140+ await removeLocalDownload ( )
141+ } )
142+
96143 t . test ( `can get ${ testCollection } as admin with just one thread` , async ( st ) => {
97144 const { stderr, stdout } = await run ( 'xst' , [ 'get' , testCollection , '.' , '--threads' , '1' ] , asAdmin )
98145 if ( stderr ) {
@@ -141,8 +188,8 @@ test('with test collection', async (t) => {
141188 )
142189 st . equal (
143190 lines . filter ( ( l ) => / ^ ✔ ︎ d o w n l o a d e d r e s o u r c e [ / \w ] + \/ g e t - t e s t / . exec ( l ) ) . length ,
144- 9 ,
145- 'notify 9 resources downloaded'
191+ 10 ,
192+ 'notify 10 resources downloaded'
146193 )
147194
148195 st . deepEqual ( readdirSync ( testCollectionName ) , expectedDirectoryListing , 'all files were downloaded' )
0 commit comments