|
| 1 | +// tslint:disable:no-console |
| 2 | +import * as v4 from '..'; |
| 3 | + |
| 4 | +console.log('=== Testing NFSv4 Formatters ===\n'); |
| 5 | + |
| 6 | +console.log('--- Constants Formatters ---'); |
| 7 | +console.log('Nfsv4Stat.NFS4_OK:', v4.formatNfsv4Stat(v4.Nfsv4Stat.NFS4_OK)); |
| 8 | +console.log('Nfsv4Stat.NFS4ERR_NOENT:', v4.formatNfsv4Stat(v4.Nfsv4Stat.NFS4ERR_NOENT)); |
| 9 | +console.log('Nfsv4Op.GETATTR:', v4.formatNfsv4Op(v4.Nfsv4Op.GETATTR)); |
| 10 | +console.log('Nfsv4Op.SETATTR:', v4.formatNfsv4Op(v4.Nfsv4Op.SETATTR)); |
| 11 | +console.log('Nfsv4FType.NF4REG:', v4.formatNfsv4FType(v4.Nfsv4FType.NF4REG)); |
| 12 | +console.log('Nfsv4FType.NF4DIR:', v4.formatNfsv4FType(v4.Nfsv4FType.NF4DIR)); |
| 13 | +console.log(); |
| 14 | + |
| 15 | +console.log('--- Attribute Formatters ---'); |
| 16 | +console.log('FATTR4_TYPE:', v4.formatNfsv4Attr(v4.Nfsv4Attr.FATTR4_TYPE)); |
| 17 | +console.log('FATTR4_SIZE:', v4.formatNfsv4Attr(v4.Nfsv4Attr.FATTR4_SIZE)); |
| 18 | +console.log('FATTR4_MODE:', v4.formatNfsv4Attr(v4.Nfsv4Attr.FATTR4_MODE)); |
| 19 | +console.log(); |
| 20 | + |
| 21 | +console.log('--- Bitmap Formatter ---'); |
| 22 | +const bitmap = new v4.Nfsv4Bitmap([0x0000001e]); |
| 23 | +console.log('Bitmap [0x0000001E]:', v4.formatNfsv4Bitmap(bitmap)); |
| 24 | +const bitmap2 = new v4.Nfsv4Bitmap([0x00000012]); |
| 25 | +console.log('Bitmap [0x00000012]:', v4.formatNfsv4Bitmap(bitmap2)); |
| 26 | +console.log(); |
| 27 | + |
| 28 | +console.log('--- Access Flags Formatter ---'); |
| 29 | +console.log('READ|LOOKUP:', v4.formatNfsv4Access(v4.Nfsv4Access.ACCESS4_READ | v4.Nfsv4Access.ACCESS4_LOOKUP)); |
| 30 | +console.log('MODIFY|EXTEND:', v4.formatNfsv4Access(v4.Nfsv4Access.ACCESS4_MODIFY | v4.Nfsv4Access.ACCESS4_EXTEND)); |
| 31 | +console.log(); |
| 32 | + |
| 33 | +console.log('--- Mode Formatter ---'); |
| 34 | +console.log('0755:', v4.formatNfsv4Mode(0o755)); |
| 35 | +console.log('0644:', v4.formatNfsv4Mode(0o644)); |
| 36 | +console.log(); |
| 37 | + |
| 38 | +console.log('--- Request Formatters ---'); |
| 39 | +const getattrReq = new v4.Nfsv4GetattrRequest(new v4.Nfsv4Bitmap([0x0000001e])); |
| 40 | +console.log('GETATTR request:', v4.formatNfsv4Request(getattrReq)); |
| 41 | + |
| 42 | +const setattrReq = new v4.Nfsv4SetattrRequest( |
| 43 | + new v4.Nfsv4Stateid(0, new Uint8Array(12)), |
| 44 | + new v4.Nfsv4Fattr(new v4.Nfsv4Bitmap([0x00000010]), new Uint8Array(8)), |
| 45 | +); |
| 46 | +console.log('SETATTR request:', v4.formatNfsv4Request(setattrReq)); |
| 47 | + |
| 48 | +const lookupReq = new v4.Nfsv4LookupRequest('file.txt'); |
| 49 | +console.log('LOOKUP request:', v4.formatNfsv4Request(lookupReq)); |
| 50 | + |
| 51 | +const accessReq = new v4.Nfsv4AccessRequest(v4.Nfsv4Access.ACCESS4_READ | v4.Nfsv4Access.ACCESS4_EXECUTE); |
| 52 | +console.log('ACCESS request:', v4.formatNfsv4Request(accessReq)); |
| 53 | +console.log(); |
| 54 | + |
| 55 | +console.log('--- Response Formatters ---'); |
| 56 | +const getattrRes = new v4.Nfsv4GetattrResponse( |
| 57 | + v4.Nfsv4Stat.NFS4_OK, |
| 58 | + new v4.Nfsv4GetattrResOk(new v4.Nfsv4Fattr(new v4.Nfsv4Bitmap([0x0000001e]), new Uint8Array(32))), |
| 59 | +); |
| 60 | +console.log('GETATTR response:', v4.formatNfsv4Response(getattrRes)); |
| 61 | + |
| 62 | +const setattrRes = new v4.Nfsv4SetattrResponse( |
| 63 | + v4.Nfsv4Stat.NFS4_OK, |
| 64 | + new v4.Nfsv4SetattrResOk(new v4.Nfsv4Bitmap([0x00000010])), |
| 65 | +); |
| 66 | +console.log('SETATTR response:', v4.formatNfsv4Response(setattrRes)); |
| 67 | + |
| 68 | +const lookupRes = new v4.Nfsv4LookupResponse(v4.Nfsv4Stat.NFS4_OK); |
| 69 | +console.log('LOOKUP response:', v4.formatNfsv4Response(lookupRes)); |
| 70 | + |
| 71 | +const accessRes = new v4.Nfsv4AccessResponse( |
| 72 | + v4.Nfsv4Stat.NFS4_OK, |
| 73 | + new v4.Nfsv4AccessResOk(0x3f, v4.Nfsv4Access.ACCESS4_READ | v4.Nfsv4Access.ACCESS4_EXECUTE), |
| 74 | +); |
| 75 | +console.log('ACCESS response:', v4.formatNfsv4Response(accessRes)); |
| 76 | +console.log(); |
| 77 | + |
| 78 | +console.log('--- Compound Request/Response Formatters ---'); |
| 79 | +const compoundReq = new v4.Nfsv4CompoundRequest('test', 0, [new v4.Nfsv4PutrootfhRequest(), lookupReq, getattrReq]); |
| 80 | +console.log('COMPOUND request:', v4.formatNfsv4CompoundRequest(compoundReq)); |
| 81 | + |
| 82 | +const compoundRes = new v4.Nfsv4CompoundResponse(v4.Nfsv4Stat.NFS4_OK, 'test', [ |
| 83 | + new v4.Nfsv4PutrootfhResponse(v4.Nfsv4Stat.NFS4_OK), |
| 84 | + lookupRes, |
| 85 | + getattrRes, |
| 86 | +]); |
| 87 | +console.log('COMPOUND response:', v4.formatNfsv4CompoundResponse(compoundRes)); |
| 88 | + |
| 89 | +console.log('\n=== All formatters tested successfully! ==='); |
0 commit comments