5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 19:26:21 +00:00

Arreglar y agregar tests

This commit is contained in:
f 2021-08-07 18:25:54 -03:00
parent 4ea2169c68
commit b9d7a27105
7 changed files with 159 additions and 46 deletions

View file

@ -9,11 +9,11 @@ FactoryBot.define do
licencia
after :build do |site|
site.deploys << build(:deploy_local, site: site)
end
after :create do |site|
site.deploys << create(:deploy_local, site: site)
# XXX: Generamos un DeployLocal normalmente y no a través de una
# Factory porque necesitamos que el sitio se genere solo.
#
# @see {https://github.com/thoughtbot/factory_bot/wiki/How-factory_bot-interacts-with-ActiveRecord}
site.deploys.build(type: 'DeployLocal')
end
end
end

View file

@ -2,11 +2,7 @@
class DeployJobTest < ActiveSupport::TestCase
test 'se puede compilar' do
rol = create :rol
site = rol.site
site.deploys << create(:deploy_zip, site: site)
site.save
site = create :site
DeployJob.perform_async(site.id)

View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'test_helper'
class DeployAlternativeDomainTest < ActiveSupport::TestCase
setup do
@site = create :site
@deploy_alt = @site.deploys.build type: 'DeployAlternativeDomain'
end
teardown do
@site&.destroy
end
def random_tld
PAK::ValidatesHostname::ALLOWED_TLDS.sample
end
test 'el hostname se ingresa manualmente' do
assert_nil @deploy_alt.hostname
end
test 'el hostname es obligatorio' do
assert_not @deploy_alt.valid?
end
test 'el hostname es válido' do
assert_not @deploy_alt.update(hostname: ' ')
assert_not @deploy_alt.update(hostname: 'custom.domain.root.')
assert_not @deploy_alt.update(hostname: 'custom.domain')
assert @deploy_alt.update(hostname: "custom.domain.#{random_tld}")
end
test 'el hostname tiene que ser único' do
assert_not @deploy_alt.update(hostname: @site.hostname)
end
test 'se puede deployear' do
assert @site.deploy_local.deploy
assert @deploy_alt.update(hostname: "#{SecureRandom.hex}.sutty.#{random_tld}")
assert @deploy_alt.deploy
assert File.symlink?(@deploy_alt.destination)
end
end

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'test_helper'
class DeployHiddenServiceTest < ActiveSupport::TestCase
setup do
@site = create :site
@deploy_hidden = @site.deploys.build type: 'DeployHiddenService'
end
teardown do
@site&.destroy
end
test 'el hostname es válido' do
assert_not @deploy_hidden.update(hostname: ' ')
assert_not @deploy_hidden.update(hostname: 'custom.domain.root.')
assert_not @deploy_hidden.update(hostname: 'custom.domain')
assert @deploy_hidden.update(hostname: "#{@deploy_hidden.send(:random_base32, 56)}.onion")
end
test 'los hostnames pueden ser temporales' do
assert @deploy_hidden.hostname.start_with? 'temporal'
end
test 'el hostname tiene que ser único' do
assert @deploy_hidden.save
assert_not @site.deploys.create(type: 'DeployHiddenService', hostname: @deploy_hidden.hostname).valid?
end
test 'se puede deployear' do
assert @site.deploy_local.deploy
assert @deploy_hidden.deploy
assert File.symlink?(@deploy_hidden.destination)
end
end

View file

@ -1,24 +1,44 @@
# frozen_string_literal: true
require 'test_helper'
class DeployLocalTest < ActiveSupport::TestCase
setup do
@site = create :site
end
teardown do
@site&.destroy
end
test 'se pueden crear' do
assert @site.deploy_local.valid?
assert_equal @site.hostname, @site.deploy_local.hostname
end
test 'no se puede cambiar el hostname' do
hostname = @site.deploy_local.hostname
@site.deploy_local.hostname = SecureRandom.hex
assert @site.deploy_local.save
assert_equal hostname, @site.deploy_local.hostname
end
test 'se puede deployear' do
site = create :site
local = create :deploy_local, site: site
deploy = create :deploy_zip, site: site
deploy_local = @site.deploy_local
# Primero tenemos que generar el sitio
local.deploy
assert deploy_local.deploy
assert File.directory?(deploy_local.destination)
assert File.exist?(File.join(deploy_local.destination, 'index.html'))
assert_equal 3, deploy_local.build_stats.count
escaped_path = Shellwords.escape(deploy.path)
assert deploy_local.build_stats.map(&:bytes).compact.inject(:+).positive?
assert deploy_local.build_stats.map(&:seconds).compact.inject(:+).positive?
end
assert deploy.deploy
assert File.file?(deploy.path)
assert_equal 'application/zip',
`file --mime-type "#{escaped_path}"`.split(' ').last
assert_equal 1, deploy.build_stats.count
assert deploy.build_stats.map(&:bytes).inject(:+).positive?
assert deploy.build_stats.map(&:seconds).inject(:+).positive?
local.destroy
test 'al eliminarlos se elimina el directorio' do
deploy_local = @site.deploy_local
assert deploy_local.destroy
assert_not File.directory?(deploy_local.destination)
end
end

View file

@ -3,17 +3,23 @@
require 'test_helper'
class DeployWwwTest < ActiveSupport::TestCase
setup do
@site = create :site
@deploy_www = @site.deploys.create type: 'DeployWww'
end
teardown do
@site&.destroy
end
test 'el hostname empieza con www' do
assert @deploy_www.hostname.start_with?('www.')
end
test 'se puede deployear' do
site = create :site
local = create :deploy_local, site: site
deploy = create :deploy_www, site: site
assert @site.deploy_local.deploy
# Primero tenemos que generar el sitio
local.deploy
assert deploy.deploy
assert File.symlink?(deploy.destination)
local.destroy
assert @deploy_www.deploy
assert File.symlink?(@deploy_www.destination)
end
end

View file

@ -3,18 +3,29 @@
require 'test_helper'
class DeployZipTest < ActiveSupport::TestCase
setup do
@site = create :site
@deploy_zip = @site.deploys.create(type: 'DeployZip')
end
teardown do
@site&.destroy
end
test 'el nombre es el hostname.zip' do
assert_equal "#{@site.hostname}.zip", @deploy_zip.hostname
end
test 'se puede deployear' do
deploy_local = create :deploy_local
# Primero tenemos que generar el sitio
assert @site.deploy_local.deploy
assert deploy_local.deploy
assert File.directory?(deploy_local.destination)
assert File.exist?(File.join(deploy_local.destination, 'index.html'))
assert_equal 3, deploy_local.build_stats.count
assert deploy_local.build_stats.map(&:bytes).compact.inject(:+).positive?
assert deploy_local.build_stats.map(&:seconds).compact.inject(:+).positive?
assert deploy_local.destroy
assert_not File.directory?(deploy_local.destination)
assert @deploy_zip.deploy
assert File.file?(@deploy_zip.path)
assert_equal 'application/zip',
`file --mime-type "#{@deploy_zip.path}"`.split.last
assert_equal 1, @deploy_zip.build_stats.count
assert @deploy_zip.build_stats.map(&:bytes).inject(:+).positive?
assert @deploy_zip.build_stats.map(&:seconds).inject(:+).positive?
end
end