git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

test.coffee (16611B)


      1 gitoff = require '../src/gitoff'
      2 assert = require('chai').assert
      3 fs     = require('fs')
      4 
      5 # all tests are independent
      6 
      7 #TODO Remove
      8 describe 'Array', ->
      9   describe '#indexOf()', ->
     10     it 'should return -1 when the value is not present', ->
     11       assert.equal -1, [
     12         1
     13         2
     14         3
     15       ].indexOf(4)
     16       return
     17     return
     18   return
     19 #TODO Remove
     20 
     21 # expandHome: expandHome
     22 describe 'expandHome', ->
     23   describe '/tmp/gitoff', ->
     24     it 'should return /tmp/gitoff', ->
     25       path = '/tmp/gitoff'
     26       assert.equal path, gitoff.expandHome(path)
     27       return
     28     return
     29   describe '~/', ->
     30     it 'should return process.env.HOME/', ->
     31       path = '~/'
     32       assert.equal process.env.HOME + '/', gitoff.expandHome(path)
     33       return
     34     return
     35   describe '~/.gitoff/o', ->
     36     it 'should return process.env.HOME/.gitoff/o', ->
     37       path = '~/.gitoff/o'
     38       assert.equal process.env.HOME + '/.gitoff/o', gitoff.expandHome(path)
     39       return
     40     return
     41   return
     42 
     43 # gitConfig: gitConfig
     44 describe 'gitConfig', ->
     45   describe 'set', ->
     46     it 'should set global variable off.test value: value', ->
     47       gitoff.gitConfig.set 'off.test', 'value'
     48       result = gitoff.exec('gitConfig', ['--file ~/.gitconfig', 'off.test']).stdout.trim()
     49       assert.equal 'value', result
     50       return
     51     return
     52   describe 'setLocal', ->
     53     it 'should set value in local .git/config: value2', ->
     54       gitoff.gitConfig.setLocal 'off.test', 'value2'
     55       result = gitoff.exec('gitConfig', ['--file ../.git/config', 'off.test']).stdout.trim()
     56       assert.equal 'value2', result
     57       return
     58     return
     59   describe 'setThisRepo', ->
     60     it 'should set value in ../.git-off: value3', ->
     61       gitoff.gitConfig.setThisRepo 'off.testrepo', 'value3'
     62       result = gitoff.exec('gitConfig', ['--file ../.git-off', 'off.testrepo']).stdout.trim()
     63       assert.equal 'value3', result
     64       return
     65     return
     66   describe 'get', ->
     67     it 'should return value from repo .git-off config', ->
     68       result = gitoff.gitConfig.get 'off.testrepo'
     69       assert.equal 'value3', result
     70       return
     71     it 'should return value from global config when the key is in not in .git-off', ->
     72       result = gitoff.gitConfig.get 'off.test'
     73       assert.equal 'value2', result
     74       return
     75     return
     76   describe 'getSyncexec', ->
     77     it "should return '' when key is not in global config", ->
     78       # getting off.testrepo in local config
     79       # returns '' because it is not found in global config
     80       result = gitoff.gitConfig.getSyncexec 'off.testrepo'
     81       assert.equal '', result.stdout.trim()
     82       return
     83     it 'should return value from global config', ->
     84       # getting off.testrepo in local config
     85       # returns '' because it is not found in global config
     86       result = gitoff.gitConfig.getSyncexec 'off.test'
     87       assert.equal 'value2', result.stdout.trim()
     88       return
     89     return
     90   return
     91 
     92 # skip offLog: offLog
     93 # skip offLogRepo: offLogRepo
     94 # skip exec: exec
     95 
     96 # mkdirParents: mkdirParents
     97 # rmAll: rmAll
     98 describe 'mkdirParents and rmAll', ->
     99   describe 'mkdirParents', ->
    100     it 'should create parent directories', ->
    101       gitoff.mkdirParents 'test/test'
    102       assert.isOk fs.existsSync('test/test'), 'test/test directory not found'
    103       return
    104     return
    105   describe 'rmAll', ->
    106     it 'should remove parent directories', ->
    107       gitoff.rmAll 'test'
    108       assert.isNotOk fs.existsSync('test'), 'test directory found'
    109       return
    110     return
    111   return
    112 
    113 # copy: copy
    114 describe 'copy', ->
    115   it 'should copy file', ->
    116     gitoff.mkdirParents 'test'
    117     gitoff.copy('../package.json', 'test/package.json')
    118     assert.isOk fs.existsSync('test/package.json'), 'test/package.json not found'
    119     gitoff.rmAll 'test'
    120     return
    121   return
    122 
    123 # walkSync: walkSync
    124 describe 'walkSync', ->
    125   it 'should list all files in a directory recursively', ->
    126     gitoff.mkdirParents 'test/test'
    127     gitoff.mkdirParents 'test/test2'
    128     gitoff.copy('../package.json', 'test/package.json')
    129     gitoff.copy('../package.json', 'test/test/package1.json')
    130     gitoff.copy('../package.json', 'test/test2/package2.json')
    131     result = gitoff.walkSync 'test'
    132     expected = ['test/package.json', 'test/test/package1.json', 'test/test2/package2.json']
    133     assert.sameMembers expected, result, 'incorrect file list (gitoff.copy is async, timing errors occur)'
    134     gitoff.rmAll 'test'
    135     return
    136   return
    137 
    138 # offHelpers: offHelpers
    139 describe 'offHelpers', ->
    140   describe 'gitRepoRoot', ->
    141     it 'should return git root and set gitoff.runtimeConfig.currentRepoRoot', ->
    142       result = gitoff.offHelpers.gitRepoRoot()
    143       r_l    = result.split('/')
    144       len    = r_l.length
    145       assert.equal 'gitoff', r_l[len-1]
    146       assert.equal gitoff.runtimeConfig.currentRepoRoot, result
    147       return
    148     return
    149   describe 'objectPath', ->
    150     it 'should return objectPath and set gitoff.runtimeConfig.objectPath', ->
    151       result = gitoff.offHelpers.objectPath()
    152       assert.equal gitoff.offHelpers.gitRepoRoot() + gitoff.offDEFAULTS.objectPath, result
    153       assert.equal gitoff.runtimeConfig.objectPath, result
    154       return
    155     return
    156   describe 'offStore', ->
    157     it 'should return off.store and set gitoff.runtimeConfig.offStore', ->
    158       result = gitoff.offHelpers.offStore()
    159       assert.equal '', result
    160       gitoff.gitConfig.setLocal 'off.store', '/gitoff/test/'
    161       result = gitoff.offHelpers.offStore()
    162       assert.equal '/gitoff/test/', result
    163       assert.equal gitoff.runtimeConfig.offStore, result
    164       return
    165     return
    166   describe 'offHttp', ->
    167     it 'should return off.http and set gitoff.runtimeConfig.offHttp', ->
    168       result = gitoff.offHelpers.offHttp()
    169       assert.equal '', result
    170       gitoff.gitConfig.setLocal 'off.http', 'http://localhost/gitoff/test/'
    171       result = gitoff.offHelpers.offHttp()
    172       assert.equal 'http://localhost/gitoff/test/', result
    173       assert.equal gitoff.runtimeConfig.offHttp, result
    174       return
    175     return
    176   describe 'offCurlOptions', ->
    177     it 'should return off.curloptions and set gitoff.runtimeConfig.offCurlOptions', ->
    178       result = gitoff.offHelpers.offCurlOptions()
    179       assert.equal '', result
    180       gitoff.gitConfig.setLocal 'off.curloptions', '-test -test2'
    181       result = gitoff.offHelpers.offCurlOptions()
    182       assert.equal '-test -test2', result
    183       assert.equal gitoff.runtimeConfig.offCurlOptions, result
    184       return
    185     return
    186   describe 'offMode', ->
    187     it 'should return off.mode and set gitoff.runtimeConfig.offMode', ->
    188       result = gitoff.offHelpers.offMode()
    189       assert.equal '', result
    190       gitoff.gitConfig.setLocal 'off.mode', 'test'
    191       result = gitoff.offHelpers.offMode()
    192       assert.equal 'test', result
    193       assert.equal gitoff.runtimeConfig.offMode, result
    194       return
    195     return
    196   describe 'offIntegrity', ->
    197     it 'should return off.integrity and set gitoff.runtimeConfig.offIntegrity', ->
    198       result = gitoff.offHelpers.offIntegrity()
    199       assert.equal '', result
    200       gitoff.gitConfig.setLocal 'off.integrity', 'enable'
    201       result = gitoff.offHelpers.offIntegrity()
    202       assert.equal 'enable', result
    203       assert.equal gitoff.runtimeConfig.offIntegrity, result
    204       return
    205     return
    206   describe 'offPem', ->
    207     it 'should return off.pem and set gitoff.runtimeConfig.offPem', ->
    208       result = gitoff.offHelpers.offPem()
    209       assert.equal '', result
    210       gitoff.gitConfig.setLocal 'off.pem', '~/test'
    211       result = gitoff.offHelpers.offPem()
    212       expected = gitoff.expandHome '~/test'
    213       assert.equal expected, result
    214       assert.equal gitoff.runtimeConfig.offPem, result
    215       return
    216     return
    217   describe 'offSshOptions', ->
    218     it 'should return off.sshoptions and set gitoff.runtimeConfig.offSshOptions', ->
    219       result = gitoff.offHelpers.offSshOptions()
    220       assert.equal '', result
    221       gitoff.gitConfig.setLocal 'off.sshoptions', 'test'
    222       result = gitoff.offHelpers.offSshOptions()
    223       assert.equal 'test', result
    224       assert.equal gitoff.runtimeConfig.offSshOptions, result
    225       return
    226     return
    227   describe 'offScpOptions', ->
    228     it 'should return off.scpoptions and set gitoff.runtimeConfig.offScpOptions', ->
    229       result = gitoff.offHelpers.offScpOptions()
    230       assert.equal '', result
    231       gitoff.gitConfig.setLocal 'off.scpoptions', 'test'
    232       result = gitoff.offHelpers.offScpOptions()
    233       assert.equal 'test', result
    234       assert.equal gitoff.runtimeConfig.offScpOptions, result
    235       return
    236     return
    237   describe 'offScp', ->
    238     it 'should return off.scphost and set gitoff.runtimeConfig.offScp', ->
    239       result = gitoff.offHelpers.offScp()
    240       assert.equal '', result
    241       gitoff.gitConfig.setLocal 'off.scphost', 'test'
    242       result = gitoff.offHelpers.offScp()
    243       assert.equal 'test', result
    244       assert.equal gitoff.runtimeConfig.offScp, result
    245       return
    246     return
    247   describe 'offScpUser', ->
    248     it 'should return off.scpuser and set gitoff.runtimeConfig.offScpUser', ->
    249       result = gitoff.offHelpers.offScpUser()
    250       assert.equal '', result
    251       gitoff.gitConfig.setLocal 'off.scpuser', 'test'
    252       result = gitoff.offHelpers.offScpUser()
    253       assert.equal 'test', result
    254       assert.equal gitoff.runtimeConfig.offScpUser, result
    255       return
    256     return
    257   describe 'log', ->
    258     it 'should return off.log and set gitoff.runtimeConfig.log', ->
    259       result = gitoff.offHelpers.log()
    260       assert.equal '', result
    261       gitoff.gitConfig.setLocal 'off.log', '~/test'
    262       result = gitoff.offHelpers.log()
    263       expected = gitoff.expandHome '~/test'
    264       assert.equal expected, result
    265       assert.equal gitoff.runtimeConfig.log, result
    266       return
    267     return
    268   # skip getLog
    269   describe 'offConfigAlways', ->
    270     it 'should return off.configAlways and set gitoff.runtimeConfig.offConfigAlways', ->
    271       result = gitoff.offHelpers.offConfigAlways()
    272       assert.equal '', result
    273       gitoff.gitConfig.set 'off.configAlways', 'test'
    274       result = gitoff.offHelpers.offConfigAlways()
    275       assert.equal 'test', result
    276       assert.equal gitoff.runtimeConfig.offConfigAlways, result
    277       return
    278     return
    279   describe 's3Region', ->
    280     it 'should return off.s3region and set gitoff.runtimeConfig.s3Region', ->
    281       result = gitoff.offHelpers.s3Region()
    282       assert.equal '', result
    283       gitoff.gitConfig.setLocal 'off.s3region', 'test'
    284       result = gitoff.offHelpers.s3Region()
    285       assert.equal 'test', result
    286       assert.equal gitoff.runtimeConfig.s3Region, result
    287       return
    288     return
    289   describe 'userAt', ->
    290     it 'should return off.scpuser@', ->
    291       gitoff.gitConfig.setLocal 'off.scpuser', 'test'
    292       user   = gitoff.offHelpers.offScpUser()
    293       result = gitoff.offHelpers.userAt()
    294       assert.equal user+'@', result
    295       return
    296     return
    297   describe 'getSSHConfig', ->
    298     it 'should return user@scphost and store path', ->
    299       # reset offScp
    300       gitoff.runtimeConfig.offScp = ''
    301       gitoff.gitConfig.setLocal 'off.scphost', 'test:store'
    302       gitoff.gitConfig.setLocal 'off.scpuser', 'test'
    303       result   = gitoff.offHelpers.getSSHConfig()
    304       expected = [ 'test@test', 'store', NaN ]
    305       assert.equal expected[0], result[0]
    306       assert.equal expected[1], result[1]
    307       assert.isOk isNaN result[2]
    308       return
    309     it 'should return user@scphost, store path and port', ->
    310       # reset offScp
    311       gitoff.runtimeConfig.offScp = ''
    312       gitoff.gitConfig.setLocal 'off.scphost', 'test:9999/tmp/store'
    313       gitoff.gitConfig.setLocal 'off.scpuser', 'test'
    314       result   = gitoff.offHelpers.getSSHConfig()
    315       expected = [ 'test@test', '/tmp/store', 9999 ]
    316       assert.sameMembers expected, result
    317       return
    318     return
    319   # TODO mkdirStore
    320   # TODO rmAllStore
    321   # TODO copyTo
    322   # TODO checkIntegrity
    323   # TODO setTransport
    324   describe 'getOffFilePath', ->
    325     it 'should return hash directories and file name', ->
    326       result = gitoff.offHelpers.getOffFilePath('00112233')
    327       expected = ['00/11/00112233', '00/11']
    328       assert.sameMembers expected, result
    329       return
    330     return
    331   return
    332 
    333 # skip - tested in setTransport - transport: transport
    334 
    335 # offCommands: offCommands
    336 describe 'offCommands', ->
    337   # TODO add process.argv as parameter to offCommands functions
    338   # TODO localSetup
    339   # TODO install
    340   describe 'mode', ->
    341     it 'should set mode', ->
    342       process.argv.push 'ctest'
    343       gitoff.offCommands.mode(gitoff.gitConfig['setLocal'])
    344       gitoff.runtimeConfig.offMode = ''
    345       result = gitoff.offHelpers.offMode()
    346       assert.equal 'ctest', result
    347       return
    348     return
    349   describe 'store', ->
    350     it 'should set store', ->
    351       process.argv.push 'ctest'
    352       gitoff.offCommands.store(gitoff.gitConfig['setThisRepo'])
    353       gitoff.runtimeConfig.offStore = ''
    354       result = gitoff.offHelpers.offStore()
    355       assert.equal 'ctest', result
    356       return
    357     return
    358   describe 'scp', ->
    359     it 'should set scp', ->
    360       process.argv.push 'ctest'
    361       gitoff.offCommands.scp(gitoff.gitConfig['setLocal'])
    362       gitoff.runtimeConfig.offScp = ''
    363       result = gitoff.offHelpers.offScp()
    364       assert.equal 'ctest', result
    365       return
    366     return
    367   describe 'http', ->
    368     it 'should set http', ->
    369       process.argv.push 'ctest'
    370       gitoff.offCommands.http(gitoff.gitConfig['setLocal'])
    371       gitoff.runtimeConfig.offHttp = ''
    372       result = gitoff.offHelpers.offHttp()
    373       assert.equal 'ctest', result
    374       return
    375     return
    376   describe 'curl', ->
    377     it 'should set curl', ->
    378       process.argv.push 'ctest'
    379       gitoff.offCommands.curl(gitoff.gitConfig['setLocal'])
    380       gitoff.runtimeConfig.offCurlOptions = ''
    381       result = gitoff.offHelpers.offCurlOptions()
    382       assert.equal 'ctest', result
    383       return
    384     return
    385   describe 'integrity', ->
    386     it 'should set integrity', ->
    387       process.argv.push 'ctest'
    388       gitoff.offCommands.integrity(gitoff.gitConfig['setLocal'])
    389       gitoff.runtimeConfig.offIntegrity = ''
    390       result = gitoff.offHelpers.offIntegrity()
    391       assert.equal 'ctest', result
    392       return
    393     return
    394   describe 'pem', ->
    395     it 'should set pem', ->
    396       process.argv.push 'ctest'
    397       gitoff.offCommands.pem(gitoff.gitConfig['setLocal'])
    398       gitoff.runtimeConfig.offPem = ''
    399       result = gitoff.offHelpers.offPem()
    400       assert.equal 'ctest', result
    401       return
    402     return
    403   describe 'sshoptions', ->
    404     it 'should set sshoptions', ->
    405       process.argv.push 'ctest'
    406       gitoff.offCommands.sshoptions(gitoff.gitConfig['setLocal'])
    407       gitoff.runtimeConfig.offSshOptions = ''
    408       result = gitoff.offHelpers.offSshOptions()
    409       assert.equal 'ctest', result
    410       return
    411     return
    412   describe 'scpoptions', ->
    413     it 'should set scpoptions', ->
    414       process.argv.push 'ctest'
    415       gitoff.offCommands.scpoptions(gitoff.gitConfig['setLocal'])
    416       gitoff.runtimeConfig.offScpOptions = ''
    417       result = gitoff.offHelpers.offScpOptions()
    418       assert.equal 'ctest', result
    419       return
    420     return
    421   describe 'scpUser', ->
    422     it 'should set scpUser', ->
    423       process.argv.push 'ctest'
    424       gitoff.offCommands.scpUser(gitoff.gitConfig['setLocal'])
    425       gitoff.runtimeConfig.offScpUser = ''
    426       result = gitoff.offHelpers.offScpUser()
    427       assert.equal 'ctest', result
    428       return
    429     return
    430   # TODO track
    431   describe 'track', ->
    432     it 'should create .gitattributes', ->
    433       process.argv.push '*.ctest'
    434       gitoff.offCommands.track()
    435       assert.isOk fs.existsSync(gitoff.offHelpers.gitRepoRoot() + '/.gitattributes'), '.gitattributes not found'
    436       return
    437     return
    438   describe 'configAlways', ->
    439     it 'should set configAlways', ->
    440       process.argv.push 'ctest'
    441       gitoff.offCommands.configAlways()
    442       gitoff.runtimeConfig.offConfigAlways = ''
    443       result = gitoff.offHelpers.offConfigAlways()
    444       assert.equal 'ctest', result
    445       return
    446     return
    447   describe 's3region', ->
    448     it 'should set s3region', ->
    449       process.argv.push 'ctest'
    450       gitoff.offCommands.s3region(gitoff.gitConfig['setLocal'])
    451       gitoff.runtimeConfig.s3Region = ''
    452       result = gitoff.offHelpers.s3Region()
    453       assert.equal 'ctest', result
    454       return
    455     return
    456   describe 's3bucket', ->
    457     it 'should set s3bucket', ->
    458       process.argv.push 'ctest'
    459       gitoff.offCommands.s3bucket(gitoff.gitConfig['setLocal'])
    460       gitoff.runtimeConfig.s3Bucket = ''
    461       result = gitoff.offHelpers.s3Bucket()
    462       assert.equal 'ctest', result
    463       return
    464     return
    465   # skip clean
    466   # skip prepush
    467   # skip push
    468   # skip smudge
    469   # skip copyTo
    470   # TODO clearAll
    471   # TODO clearCache
    472   # TODO clearStore
    473   # skip defaults
    474   # skip env
    475   # skip help
    476   return
    477 
    478 # TODO thisrepo: thisrepo
    479 # skip showCommandHelp: showCommandHelp
    480 # skip COMMAND_MAP: COMMAND_MAP