@@ -705,3 +705,119 @@ describe('.opendir()', () => {
705705 await stop ( ) ;
706706 } ) ;
707707} ) ;
708+
709+ describe ( '.chmod()' , ( ) => {
710+ test ( 'can change file mode' , async ( ) => {
711+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
712+ const fs = new Nfsv4FsClient ( client ) ;
713+ await fs . chmod ( 'file.txt' , 0o644 ) ;
714+ const stats = await fs . stat ( 'file.txt' ) ;
715+ expect ( Number ( stats . mode ) & 0o777 ) . toBe ( 0o644 ) ;
716+ await stop ( ) ;
717+ } ) ;
718+
719+ test ( 'can change directory mode' , async ( ) => {
720+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
721+ const fs = new Nfsv4FsClient ( client ) ;
722+ await fs . chmod ( 'subdir' , 0o755 ) ;
723+ const stats = await fs . stat ( 'subdir' ) ;
724+ expect ( Number ( stats . mode ) & 0o777 ) . toBe ( 0o755 ) ;
725+ await stop ( ) ;
726+ } ) ;
727+
728+ test ( 'can change nested file mode' , async ( ) => {
729+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
730+ const fs = new Nfsv4FsClient ( client ) ;
731+ await fs . chmod ( 'subdir/nested.dat' , 0o600 ) ;
732+ const stats = await fs . stat ( 'subdir/nested.dat' ) ;
733+ expect ( Number ( stats . mode ) & 0o777 ) . toBe ( 0o600 ) ;
734+ await stop ( ) ;
735+ } ) ;
736+ } ) ;
737+
738+ describe ( '.chown()' , ( ) => {
739+ test ( 'can change file owner' , async ( ) => {
740+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
741+ const fs = new Nfsv4FsClient ( client ) ;
742+ await fs . chown ( 'file.txt' , 1001 , 1001 ) ;
743+ await stop ( ) ;
744+ } ) ;
745+
746+ test ( 'can change directory owner' , async ( ) => {
747+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
748+ const fs = new Nfsv4FsClient ( client ) ;
749+ await fs . chown ( 'subdir' , 1002 , 1002 ) ;
750+ await stop ( ) ;
751+ } ) ;
752+
753+ test ( 'can change nested file owner' , async ( ) => {
754+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
755+ const fs = new Nfsv4FsClient ( client ) ;
756+ await fs . chown ( 'subdir/nested.dat' , 1003 , 1003 ) ;
757+ await stop ( ) ;
758+ } ) ;
759+ } ) ;
760+
761+ describe ( '.lchmod()' , ( ) => {
762+ test ( 'can change file mode without following symlinks' , async ( ) => {
763+ const { client, stop, vol} = await setupNfsClientServerTestbed ( ) ;
764+ const fs = new Nfsv4FsClient ( client ) ;
765+ vol . symlinkSync ( 'file.txt' , '/export/link.txt' ) ;
766+ await fs . lchmod ( 'link.txt' , 0o777 ) ;
767+ const stats = await fs . lstat ( 'link.txt' ) ;
768+ expect ( stats . isSymbolicLink ( ) ) . toBe ( true ) ;
769+ await stop ( ) ;
770+ } ) ;
771+
772+ test ( 'can change regular file mode with lchmod' , async ( ) => {
773+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
774+ const fs = new Nfsv4FsClient ( client ) ;
775+ await fs . lchmod ( 'file.txt' , 0o666 ) ;
776+ const stats = await fs . stat ( 'file.txt' ) ;
777+ expect ( Number ( stats . mode ) & 0o777 ) . toBe ( 0o666 ) ;
778+ await stop ( ) ;
779+ } ) ;
780+ } ) ;
781+
782+ describe ( '.lchown()' , ( ) => {
783+ test ( 'can change file owner without following symlinks' , async ( ) => {
784+ const { client, stop, vol} = await setupNfsClientServerTestbed ( ) ;
785+ const fs = new Nfsv4FsClient ( client ) ;
786+ vol . symlinkSync ( 'file.txt' , '/export/link.txt' ) ;
787+ await fs . lchown ( 'link.txt' , 2001 , 2001 ) ;
788+ await stop ( ) ;
789+ } ) ;
790+
791+ test ( 'can change regular file owner with lchown' , async ( ) => {
792+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
793+ const fs = new Nfsv4FsClient ( client ) ;
794+ await fs . lchown ( 'file.txt' , 2002 , 2002 ) ;
795+ await stop ( ) ;
796+ } ) ;
797+ } ) ;
798+
799+ describe ( '.lutimes()' , ( ) => {
800+ test ( 'can update symlink times without following' , async ( ) => {
801+ const { client, stop, vol} = await setupNfsClientServerTestbed ( ) ;
802+ const fs = new Nfsv4FsClient ( client ) ;
803+ vol . symlinkSync ( 'file.txt' , '/export/link.txt' ) ;
804+ const now = Date . now ( ) ;
805+ const atime = new Date ( now - 10000 ) ;
806+ const mtime = new Date ( now - 5000 ) ;
807+ await fs . lutimes ( 'link.txt' , atime , mtime ) ;
808+ await stop ( ) ;
809+ } ) ;
810+
811+ test ( 'can update regular file times with lutimes' , async ( ) => {
812+ const { client, stop} = await setupNfsClientServerTestbed ( ) ;
813+ const fs = new Nfsv4FsClient ( client ) ;
814+ const now = Date . now ( ) ;
815+ const atime = new Date ( now - 10000 ) ;
816+ const mtime = new Date ( now - 5000 ) ;
817+ await fs . lutimes ( 'file.txt' , atime , mtime ) ;
818+ const stats = await fs . stat ( 'file.txt' ) ;
819+ expect ( Math . abs ( Number ( stats . atimeMs ) - atime . getTime ( ) ) ) . toBeLessThan ( 2000 ) ;
820+ expect ( Math . abs ( Number ( stats . mtimeMs ) - mtime . getTime ( ) ) ) . toBeLessThan ( 2000 ) ;
821+ await stop ( ) ;
822+ } ) ;
823+ } ) ;
0 commit comments