Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Automated test for `appstore`
- --local TAS_HOST = 'https://turtleappstore.com'
- local TAS_HOST = 'http://localhost:8000'
- local USERNAME = 'AlSweigart'
- local APPNAME = 'haldo'
- local PERMALINK = 'KdS3dZ'
- local OTP = '123456' -- see DEBUG_MASTER_OTP in settings/local.py
- local FILENAME = 'localhaldo'
- local BAD_PERMALINK = 'xxxxxx'
- local BAD_APPNAME = 'doesnotexist'
- local BAD_USERNAME = 'nosuchuser'
- local BAD_FILENAME = 'filedoesnotexist'
- local BAD_OTP = '999999'
- local APPHEADER = '-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME
- local result
- -- wipe existing appstore program and redownload
- shell.run('delete appstore')
- shell.run('delete .appstoreusername')
- shell.run('pastebin get iXRkjNsG appstore')
- function delAppAndCache()
- shell.run('delete ' .. APPNAME)
- shell.run('delete .appstoreusername')
- shell.run('delete ' .. FILENAME)
- end
- function cacheExists()
- if not fs.exists('.appstoreusername') then
- return false
- end
- fo = fs.open('.appstoreusername', 'r')
- username = fo.readAll()
- fo.close()
- return username == USERNAME
- end
- function createCache()
- fo = fs.open('.appstoreusername', 'w')
- fo.write(USERNAME)
- fo.close()
- end
- function createBlankApp()
- -- creates a file with the name APPNAME but with no content
- fo = fs.open(APPNAME, 'w')
- fo.write(APPHEADER)
- fo.close()
- end
- function createFilename()
- -- creates the local file app
- fo = fs.open(FILENAME, 'w')
- fo.write(APPHEADER)
- fo.write('\nprint("local haldo!")')
- fo.close()
- end
- function checkFiles(testNum)
- assert(fs.exists(APPNAME), 'T' .. testNum .. ' failed, no app')
- assert(cacheExists(), 'T' .. testNum .. ' failed, no cache')
- end
- function checkAppNotBlank(testNum)
- fo = fs.open(APPNAME, 'r')
- content = fo.readAll()
- fo.close()
- assert(content ~= APPHEADER, 'T' .. testNum .. ' failed, app is blank')
- end
- -- Test 0: Make sure you can connect
- assert(http.get(TAS_HOST) ~= nil, 'Cannot connect to ' .. TAS_HOST)
- -- Test 1: `appstore <permalink>`
- delAppAndCache()
- success = shell.run('appstore ' .. PERMALINK)
- checkFiles(1)
- -- Test 2: `appstore <OVERWRITEpermalink>`
- delAppAndCache()
- createBlankApp()
- success = shell.run('appstore ' .. PERMALINK)
- checkFiles(2)
- checkAppNotBlank(2)
- -- Test 3: `appstore <404permalink>`
- delAppAndCache()
- success = shell.run('appstore ' .. BAD_PERMALINK)
- assert(not success, 'T3 failed')
- -- Test 4: `appstore get <NOCACHEappname>`
- delAppAndCache()
- success = shell.run('appstore get ' .. APPNAME)
- assert(not success, 'T4 failed')
- -- Test 5: `appstore get <404appname>`
- delAppAndCache()
- success = shell.run('appstore get ' .. BAD_APPNAME)
- assert(not success, 'T5 failed')
- -- Test 6: `appstore get <appname>`
- delAppAndCache()
- createCache()
- success = shell.run('appstore get ' .. APPNAME)
- assert(success, 'T6 failed')
- checkFiles(6)
- -- Test 7: `appstore get <username> <appname>`
- delAppAndCache()
- success = shell.run('appstore get ' .. USERNAME .. ' ' .. APPNAME)
- assert(success, 'T7 failed')
- checkFiles(7)
- -- Test 8: `appstore get <username> <404appname>`
- delAppAndCache()
- success = shell.run('appstore get ' .. USERNAME .. ' ' .. BAD_APPNAME)
- assert(not success, 'T8 failed')
- -- Test 9: `appstore get <username> <OVERWRITEappname>`
- delAppAndCache()
- createBlankApp()
- success = shell.run('appstore get ' .. USERNAME .. ' ' .. APPNAME)
- assert(success, 'T9 failed')
- checkFiles(9)
- checkAppNotBlank(9)
- -- Test 10: `appstore get <404username> <appname>`
- delAppAndCache()
- success = shell.run('appstore get ' .. BAD_USERNAME .. ' ' .. APPNAME)
- assert(not success, 'T10 failed')
- -- Test 11: `appstore run <appname>`
- delAppAndCache()
- createCache()
- success = shell.run('appstore run ' .. APPNAME)
- assert(success, 'T11 failed')
- checkFiles(11)
- -- Test 12: `appstore run <NOCACHEappname>`
- delAppAndCache()
- success = shell.run('appstore run ' .. APPNAME)
- assert(not success, 'T12 failed')
- -- Test 13: `appstore run <OVERWRITEappname>`
- delAppAndCache()
- createCache()
- createBlankApp()
- success = shell.run('appstore run ' .. APPNAME)
- assert(success, 'T13 failed')
- checkFiles(13)
- checkAppNotBlank(13)
- -- Test 14: `appstore run <permalink>`
- --[[
- -- canceled this test, removing this feature
- delAppAndCache()
- success = shell.run('appstore run ' .. PERMALINK)
- assert(success, 'T14 failed')
- checkFiles(14)
- ]]
- -- Test 15: `appstore run <404permalink>`
- --[[
- -- canceled this test, removing this feature
- delAppAndCache()
- success = shell.run('appstore run ' .. BAD_PERMALINK)
- assert(not success, 'T15 failed')
- ]]
- -- Test 16: `appstore run <username> <appname>`
- delAppAndCache()
- success = shell.run('appstore run ' .. USERNAME .. ' ' .. APPNAME)
- assert(success, 'T16 failed')
- checkFiles(16)
- -- Test 17: `appstore run <404username> <appname>`
- delAppAndCache()
- success = shell.run('appstore run ' .. BAD_USERNAME .. ' ' .. APPNAME)
- assert(not success, 'T17 failed')
- -- Test 18: `appstore run <username> <404appname>`
- delAppAndCache()
- success = shell.run('appstore run ' .. USERNAME .. ' ' .. BAD_APPNAME)
- assert(not success, 'T18 failed')
- -- Test 19: `appstore put <filename> <otp>`
- delAppAndCache()
- createCache()
- createFilename()
- success = shell.run('appstore put ' .. FILENAME .. ' ' .. OTP)
- assert(success, 'T19 failed')
- -- Test 20: `appstore put <NOCACHEfilename> <otp>`
- delAppAndCache()
- createFilename()
- success = shell.run('appstore put ' .. FILENAME .. ' ' .. OTP)
- assert(not success, 'T20 failed')
- -- Test 21: `appstore put <404filename> <otp>`
- delAppAndCache()
- createFilename()
- createCache()
- success = shell.run('appstore put ' .. BAD_FILENAME .. ' ' .. OTP)
- assert(not success, 'T21 failed')
- -- Test 22: `appstore put <filename> <BADotp>`
- delAppAndCache()
- createFilename()
- createCache()
- success = shell.run('appstore put ' .. FILENAME .. ' ' .. BAD_OTP)
- assert(not success, 'T22 failed')
- -- Test 23: `appstore update <filename>`
- delAppAndCache()
- createBlankApp()
- createCache()
- success = shell.run('appstore update ' .. FILENAME)
- assert(not success, 'T23 failed')
- -- TODO check the new file to make sure it was updated
- -- Test 24: `appstore update <404filename>`
- delAppAndCache()
- createBlankApp()
- createCache()
- success = shell.run('appstore update ' .. BAD_FILENAME)
- assert(not success, 'T24 failed')
- -- Test 25: `appstore update <NO_HEADERfilename>`
- delAppAndCache()
- fo = fs.open(APPNAME, 'w')
- fo.close()
- createCache()
- success = shell.run('appstore update ' .. FILENAME)
- assert(not success, 'T25 failed')
- -- Test 26: `appstore updateall`
- delAppAndCache()
- fo = fs.open(APPNAME .. '1', 'w')
- fo.write('-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME .. '1')
- fo.close()
- fo = fs.open(APPNAME .. '2', 'w')
- fo.write('-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME .. '2')
- fo.close()
- createCache()
- success = shell.run('appstore updateall')
- shell.run('delete ' .. APPNAME .. '1')
- shell.run('delete ' .. APPNAME .. '2')
- assert(not success, 'T26 failed')
- -- TODO check the new file to make sure it was updated
- -- TODO check multiple files
- -- Test 27: `appstore boguscommand`
- delAppAndCache()
- success = shell.run('appstore boguscommand')
- assert(not success, 'T27 failed')
- -- Test : `appstore diff <filename>` when
- -- TODO - implement this
- -- Test : `appstore diff <404filename>` when
- -- TODO - implement this
- -- Test : `appstore diff <NO_HEADERfilename>` when
- -- TODO - implement this
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement