Commit 79dd2046 authored by Leo Iannacone's avatar Leo Iannacone

start working on tests

parent 9e107afa
......@@ -14,7 +14,8 @@
},
"scripts": {
"install": "bash scripts/install.sh",
"start": "coffee debomatic-webui"
"start": "coffee debomatic-webui",
"test": "cd test; mocha -R list --compilers coffee:coffee-script/register --require should tests.coffee"
},
"bin": {
"debomatic-webui": "./debomatic-webui"
......
fs = require('fs')
path = require('path')
spawn = require('child_process').spawn
exec = require('child_process').exec
config = require('./tests.config')
io = require('socket.io-client')
events = require('../lib/config').events
should = require('should')
server = null
launch_server = () ->
server = spawn('coffee', ['../debomatic-webui.coffee', '-c', 'test/tests.config.coffee'])
server.stdout.on 'data', (data) -> console.log('\nSERVER OUT: ', data.toString('utf-8'))
server.stderr.on 'data', (data) -> console.error('\nSERVER ERR', data.toString('utf-8'))
server.on 'exit', (code) ->
console.error('child process exited with code ' + code);
process.exit(code)
class Helper
constructor: ->
@base = config.debomatic.path
@json = config.debomatic.json
make_distribution: (distribution) ->
dpath = path.join(@base, distribution, 'pool')
exec("mkdir -p #{dpath}")
make_package: (distribution, debpack) ->
dpath = path.join(@base, distribution, 'pool', debpack)
exec("mkdir -p #{dpath}")
make_file: (distribution, debpack, extension, data) ->
file_path = path.join(@base, distribution, 'pool', debpack, debpack) + '.' + extension
@make_package(distribution, debpack)
exec("echo #{data} > #{file_path}")
append_file: (distribution, debpack, extension, data) ->
file_path = path.join(@base, distribution, 'pool', debpack, debpack) + '.' + extension
@make_package(distribution, debpack)
exec("echo #{data} >> #{file_path}")
append_json: (data) ->
exec("echo #{data} >> #{@json}")
clean: (distribution, debpack, file_extension) ->
b_path = @base
b_path = path.join(b_path, distribution, 'pool') if distribution?
b_path = path.join(@base, debpack) if debpack?
b_path = path.join(@base, debpack) + '.' + file_extension if file_extension?
exec("rm -r #{b_path}")
clean_all: () ->
exec("rm -r #{@base}/*")
exec("rm -r #{@json}")
get_query: (distribution, debpack, file_extension) ->
result =
distribution:
name: distribution
if debpack?
result.package =
orig_name: debpack
name: debpack.split('_')[0]
version: debpack.split('_')[1]
if file_extension?
result.file =
name: file_extension
return result
helper = new Helper()
helper.make_distribution('unstable')
# launch_server()
client = null
describe 'client', ->
before( (done) ->
helper.make_distribution('trusty')
helper.make_distribution('unstable')
helper.append_json("")
client = io.connect("http://#{config.host}:#{config.port}")
done()
)
it 'on getting distributions', (done) ->
client.on events.broadcast.distributions, (data) ->
data.should.be.eql(['trusty', 'unstable'])
done()
it 'on getting package list', (done) ->
helper.make_file('unstable', 'test_1.2.3', 'buildlog', 'test')
helper.make_file('unstable', 'test_1.2.3', 'lintian', 'test')
client.emit(events.client.package_files_list, helper.get_query('unstable', 'test_1.2.3'))
client.on events.client.package_files_list, (data) ->
data.distribution.name.should.be.eql('unstable')
data.package.orig_name.should.be.eql('test_1.2.3')
files_name = []
for f in data.package.files
files_name.push(f.name)
files_name.should.be.eql(['buildlog', 'lintian'])
done()
it 'on getting file', (done) ->
helper.make_file('unstable', 'test_1.2.3', 'buildlog', 'this is a test')
client.emit(events.client.file, helper.get_query('unstable', 'test_1.2.3', 'buildlog'))
client.on events.client.file, (data) ->
data.distribution.name.should.be.eql('unstable')
data.package.orig_name.should.be.eql('test_1.2.3')
data.file.name.should.be.eql('buildlog')
data.file.content.should.be.eql('this is a test\n')
done()
it 'on getting file new content', (done) ->
client.on events.client.file_newcontent, (data) ->
data.distribution.name.should.be.eql('unstable')
data.package.orig_name.should.be.eql('test_1.2.3')
data.file.name.should.be.eql('buildlog')
data.file.new_content.should.be.eql('this is an appending test\n')
done()
helper.append_file('unstable', 'test_1.2.3', 'buildlog', 'this is an appending test')
after( () ->
helper.clean_all()
)
# process.on 'exit', () ->
# server.kill()
###
debomatic-webui user configuration
###
###
Init some values, do not touch these
###
config = {}
config.debomatic = {}
config.web = {}
config.web.debomatic = {}
config.web.debomatic.admin = {}
config.web.debomatic.dput = {}
config.web.file = {}
config.web.preferences = {}
###
Configure host and port
###
config.host = "localhost"
config.port = 3030
###
Deb-O-Matic settings
###
config.debomatic.path = "debomatic/dir"
config.debomatic.jsonfile = "debomatic/json.log"
###
List of files to get a simple preview and number of lines
to show
###
config.web.file.preview = ["buildlog"]
config.web.file.num_lines = 25
# DO NOT EDIT THIS LINE:
module.exports = config
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment