Skip to content
Permalink
Browse files

Adds tests, travis support and more

  • Loading branch information...
captn3m0 committed Aug 22, 2015
1 parent ab78b5e commit e44902899c53bfbe1c685bf0f1c89797266a63cb
Showing with 63 additions and 11 deletions.
  1. +4 −0 .travis.yml
  2. +8 −1 Gemfile
  3. +7 −0 Gemfile.lock
  4. +1 −1 README.md
  5. +15 −0 app.rb
  6. +3 −0 config.ru
  7. +14 −4 config.yml
  8. +6 −0 redirects.yml
  9. +5 −5 test.rb
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.2.2
script: ruby test.rb
@@ -2,4 +2,11 @@ source "https://rubygems.org"
ruby '2.2.2'

gem 'sinatra'
gem 'minitest'

group :test do
gem 'minitest'
end

group :production do
gem 'thin'
end
@@ -1,6 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
daemons (1.2.3)
eventmachine (1.0.8)
minitest (5.7.0)
rack (1.6.4)
rack-protection (1.5.3)
@@ -9,6 +11,10 @@ GEM
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
thin (1.6.3)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0)
rack (~> 1.0)
tilt (2.0.1)

PLATFORMS
@@ -17,6 +23,7 @@ PLATFORMS
DEPENDENCIES
minitest
sinatra
thin

BUNDLED WITH
1.10.5
@@ -1,4 +1,4 @@
# lightsaber
# lightsaber [![Build Status](https://travis-ci.org/captn3m0/lightsaber.svg)](https://travis-ci.org/captn3m0/lightsaber)

Lightsaber is a simple DNS Redirect service. It offers 301/302 redirects for
your domains. The configuration is kept public on this github repository itself.
15 app.rb
@@ -0,0 +1,15 @@
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'yaml'

get '/' do
hostname = request.host
YAML::load_file('redirects.yml').each do |code, zone|
if zone.has_key? hostname
redirect zone[hostname], code
end
end

halt 404, "#{hostname} hasn't been setup yet."
end
@@ -0,0 +1,3 @@
require File.expand_path '../app.rb', __FILE__

run Sinatra::Application
@@ -1,4 +1,14 @@
301:
github.captnemo.in: https://github.com/captn3m0
302:
fb.captnemo.in: https://facebook.com/captn3m0
---
environment: production
chdir: /home/lightsaber/lightsaber
address: 127.0.0.1
user: lightsaber
group: lightsaber
port: 4567
pid: /tmp/lightsaber.pid
rackup: /home/lightsaber/lightsaber/config.ru
log: /home/lightsaber/lightsaber/thin.log
max_conns: 1024
timeout: 5
max_persistent_conns: 256
daemonize: true
@@ -0,0 +1,6 @@
---
301:
github.captnemo.in: https://github.com/captn3m0
lightsaber.captnemo.in: https://github.com/captn3m0/lightsaber
302:
fb.captnemo.in: https://facebook.com/captn3m0
10 test.rb
@@ -4,14 +4,14 @@
require 'pp'

class TestConfig < Minitest::Test
REDIRECTS = ['301', '302']
REDIRECTS = [301, 302]
def setup
@config = YAML::load_file 'config.yml'
@config = YAML::load_file 'redirects.yml'
end

def test_redirect_sections
@config.each do |section, zone|
assert REDIRECTS.include? section.to_s
@config.each do |code, zone|
assert REDIRECTS.include? code
end
end

@@ -25,7 +25,7 @@ def test_each_domain
end

def resolves_to_lightsaber(domain)
flag = false
flag = domain === "lightsaber.captnemo.in"
Resolv::DNS.open do |dns|
records = dns.getresources domain, Resolv::DNS::Resource::IN::CNAME
records.each do |record|

0 comments on commit e449028

Please sign in to comment.
You can’t perform that action at this time.