Skip to content

Commit

Permalink
Merge pull request bsmth#30 from tcob/test
Browse files Browse the repository at this point in the history
Add More Test
  • Loading branch information
Brian Thomas Smith authored Apr 15, 2018
2 parents e6f437b + 7eb7ea1 commit 05631a5
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ rvm:
- 2.4.1
- 2.5.1
before_install: gem install bundler
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
env:
global:
- CC_TEST_REPORTER_ID=780b9b8a174ce593e30d29c06b43e7b7373825f98e8140d4b8acf93818a89231
Expand Down
2 changes: 0 additions & 2 deletions lib/orgbots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require_relative 'tasks/schedule'
require_relative 'config'

Query.new.authed_ratelimit

# Run through the setup checklist before proceeding
Config.new.checklist

Expand Down
4 changes: 0 additions & 4 deletions lib/tasks/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def initialize(r, t)
@genword = RandCommit.new(r, t).genword
end

def hooks
@c.hooks(@repo)
end

def nice_commit
content = @genword
randombranch = BranchBot.new(@repo, @token).list_branches.sample
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/random_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(r, t)

def commit
content = genword
randombranch = BranchBot.new(@repo, @token).list_branches.sample
randombranch = BranchBot.new(@repo, @token).rand_branch
file = pick_file(randombranch)
file = genword.to_s + txt_ext if maybe
CommitBot.new(@repo, randombranch, @token).commit(file, content, genword)
Expand Down
23 changes: 15 additions & 8 deletions lib/tasks/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
require 'octokit'

Dotenv.load('orgbot.env')
@r = ENV['REPO']
@t = ENV['TOKEN']

def shuffle_file
message = 'shufflin'
branch = BranchBot.new(@r, @t).list_branches.sample
file = FileBot.new(@r, @t).list_files(branch).collect { |f| f[:path] }.sample
content = FileBot.new(@r, @t).get_contents(file, branch)[:content]
RandCommitter.new(@r, @t).shuffle_file(branch, file, content, message)
# Some tasks
class TaskManager
def initialize
@c = Octokit::Client.new(access_token: ENV['TOKEN'])
@r = ENV['REPO']
@t = ENV['TOKEN']
end

def shuffle_rand_file
@message = 'shufflin'
@branch = BranchBot.new(@r, @t).list_branches.sample
@file = FileBot.new(@r, @t).list_files(@branch).collect { |f| f[:path] }.sample
@content = FileBot.new(@r, @t).get_contents(@file, @branch)[:content]
RandCommit.new(@r, @t).shuffle_file(@branch, @file, @content, @message)
end
end
5 changes: 5 additions & 0 deletions lib/utils/brancher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BranchBot
def initialize(r, t)
@c = Octokit::Client.new(access_token: t)
@repo = r
@token = t
end

def list_branches
Expand All @@ -26,4 +27,8 @@ def delete_branch(branch)
@c.delete_ref(@repo, 'heads/' + branch) if list_branches.include?(branch)
puts "Deleting #{branch} from #{@repo}"
end

def rand_branch
BranchBot.new(@repo, @token).list_branches.sample.to_s
end
end
4 changes: 4 additions & 0 deletions lib/utils/queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ def user
@c = Octokit::Client.new(access_token: @t)
@c.user[:login]
end

def hooks
@c.hooks(@repo)
end
end
2 changes: 1 addition & 1 deletion lib/utils/reacter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def issue_react(issue_id, reaction)
end

def randemoji(multiple)
moji = Octokit.emojis.to_a.sample(multiple)
moji = @c.emojis.to_a.sample(multiple)
str = ''
moji.each { |a| str += ":#{a[0]}: " }
str
Expand Down
6 changes: 0 additions & 6 deletions lib/utils/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

# Some basic utilities
class Util
def ratelimit
rem = Octokit.rate_limit['remaining']
total = seconds_to_str(Octokit.rate_limit['resets_in'].to_i)
puts "#{rem} remaining requests, Rate Limit resets in #{total}"
end

def seconds_to_str(seconds)
["#{seconds / 3600}h", "#{seconds / 60 % 60}m", "#{seconds % 60}s"]
.select { |str| str =~ /[1-9]/ }.join(' ')
Expand Down
9 changes: 6 additions & 3 deletions test/suite.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require_relative 'test_dotenv'
require_relative 'test_branches'
require_relative 'test_config'
require_relative 'test_utils'
require_relative 'test_reporter'
require_relative 'test_dotenv'
require_relative 'test_issues'
require_relative 'test_pull_requests'
require_relative 'test_queries'
require_relative 'test_reporter'
require_relative 'test_utils'
25 changes: 25 additions & 0 deletions test/suppress_output.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# rubocop:disable Metrics/MethodLength

# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
#
def suppress_output
begin
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen(File.new('/dev/null', 'w'))
$stdout.reopen(File.new('/dev/null', 'w'))
retval = yield
rescue StandardError => e
$stdout.reopen(original_stdout)
$stderr.reopen(original_stderr)
raise e
ensure
$stdout.reopen(original_stdout)
$stderr.reopen(original_stderr)
end
retval
end
# rubocop:enable Metrics/MethodLength
21 changes: 21 additions & 0 deletions test/test_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'test/unit'
require 'dotenv/load'
require_relative '../lib/utils/brancher'

Dotenv.load('orgbot.env')

class TestBranches < Test::Unit::TestCase
def test_list_branches
brancher = BranchBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
puts brancher.list_branches
end
end

def test_rand_branch
brancher = BranchBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
puts brancher.rand_branch
end
end
end
28 changes: 28 additions & 0 deletions test/test_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test/unit'
require 'dotenv/load'
require_relative '../lib/utils/issues'

Dotenv.load('orgbot.env')

class TestIssues < Test::Unit::TestCase
def test_list_issues
issue = IssueBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
issue.list_issues
end
end

def test_list_open_issues
issue = IssueBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
issue.open_issues
end
end

def test_list_closed_issues
issue = IssueBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
issue.closed_issues
end
end
end
22 changes: 22 additions & 0 deletions test/test_pull_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test/unit'
require 'dotenv/load'
require_relative 'suppress_output'
require_relative '../lib/utils/pullrequest'

Dotenv.load('orgbot.env')

class TestPullRequest < Test::Unit::TestCase
def test_open_prs
pr = PRBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
suppress_output { pr.open_prs }
end
end

def test_all_pr_comments
pr = PRBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
suppress_output { pr.all_pr_comments }
end
end
end
7 changes: 7 additions & 0 deletions test/test_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ def test_user_login
query.user
end
end

def test_ratelimit
query = Query.new
assert_nothing_raised do
query.ratelimit
end
end
end
3 changes: 2 additions & 1 deletion test/test_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'test/unit'
require_relative 'suppress_output'
require_relative '../lib/utils/reporter'

class TestReporter < Test::Unit::TestCase
def test_welcome
rep = Reporter.new
assert_nothing_raised do
rep.welcome
suppress_output { rep.welcome }
end
end
end
7 changes: 0 additions & 7 deletions test/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
require_relative '../lib/utils/utils'

class TestUtils < Test::Unit::TestCase
def test_ratelimit
util = Util.new
assert_nothing_raised do
util.ratelimit
end
end

def test_time_conversion
util = Util.new
expected = '50m 2s'
Expand Down

0 comments on commit 05631a5

Please sign in to comment.