From 0e046c183afdef3be9a9f25629487817302579cf Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Tue, 10 Apr 2018 09:33:06 +0200 Subject: Update ssh_spec.rb --- spec/input/ssh_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/input/ssh_spec.rb b/spec/input/ssh_spec.rb index d86ffa0..7be9139 100644 --- a/spec/input/ssh_spec.rb +++ b/spec/input/ssh_spec.rb @@ -24,7 +24,7 @@ describe Oxidized::SSH do model = mock() model.expects(:cfg).returns({'ssh' => []}) - @node.expects(:model).returns(model) + @node.expects(:model).returns(model).at_least_once proxy = mock() Net::SSH::Proxy::Command.expects(:new).with("ssh test.com -W %h:%p").returns(proxy) -- cgit v1.2.1 From 56ba0d670100de87f94778f434d26e87fc741fa0 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 11:46:45 +0200 Subject: Update githubrepo_spec.rb to pass successfully --- spec/githubrepo_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb index 2f84c78..e676534 100644 --- a/spec/githubrepo_spec.rb +++ b/spec/githubrepo_spec.rb @@ -32,7 +32,7 @@ describe GithubRepo do describe "#fetch_and_merge_remote" do before(:each) do Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' - Rugged::Credentials::SshKeyFromAgent.expects(:new).with(username: 'git').returns(credentials) + Proc.expects(:new).returns(credentials) repo_head.expects(:name).returns('refs/heads/master') gr.cfg = Oxidized.config.hooks.github_repo_hook end @@ -89,6 +89,7 @@ describe GithubRepo do end before do + Proc.expects(:new).returns(credentials) repo_head.expects(:name).twice.returns('refs/heads/master') repo.expects(:head).twice.returns(repo_head) repo.expects(:path).returns('/foo.git') @@ -108,14 +109,14 @@ describe GithubRepo do Oxidized.config.hooks.github_repo_hook.remote_repo = 'https://github.com/username/foo.git' Oxidized.config.hooks.github_repo_hook.username = 'username' Oxidized.config.hooks.github_repo_hook.password = 'password' - Rugged::Credentials::UserPassword.expects(:new).with(username: 'username', password: 'password').returns(credentials) + Proc.expects(:new).returns(credentials) gr.cfg = Oxidized.config.hooks.github_repo_hook gr.run_hook(ctx).must_equal true end it "will push to the remote repository using ssh" do Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' - Rugged::Credentials::SshKeyFromAgent.expects(:new).with(username: 'git').returns(credentials) + Proc.expects(:new).returns(credentials) gr.cfg = Oxidized.config.hooks.github_repo_hook gr.run_hook(ctx).must_equal true end @@ -125,7 +126,7 @@ describe GithubRepo do let(:group) { 'ggrroouupp' } before do - Rugged::Credentials::SshKeyFromAgent.expects(:new).with(username: 'git').returns(credentials) + Proc.expects(:new).returns(credentials) Rugged::Repository.expects(:new).with(repository).returns(repo) repo.expects(:remotes).twice.returns(remotes) -- cgit v1.2.1 From 9850a6b6107685c6cfc95f0411a5e61e0955bf85 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 18:03:04 +0200 Subject: introduce rubocop and bump testing ecosystem --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 28eb9d4..2b49a6c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'minitest/autorun' -require 'mocha/mini_test' +require 'mocha/minitest' require 'oxidized' Oxidized.mgr = Oxidized::Manager.new -- cgit v1.2.1 From cfbc50afe8a7c1e182fb6b0b4a8dbafdd33c5ce2 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 21:41:04 +0200 Subject: ensure asetus is initialized regardless of test execution order --- spec/cli_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index eb9872e..bf6058a 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -2,8 +2,14 @@ require 'spec_helper' require 'oxidized/cli' describe Oxidized::CLI do - before { @original = ARGV } - after { ARGV.replace @original } + before(:each) do + @original = ARGV + Oxidized.asetus = Asetus.new + end + + after(:each) do + ARGV.replace @original + end %w[-v --version].each do |option| describe option do -- cgit v1.2.1 From 9ed50b5de4be4ae49c381fd539b9184631958d5b Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Thu, 19 Apr 2018 22:42:44 +0200 Subject: tidy up tests with rubocop --- spec/githubrepo_spec.rb | 31 +++++++++++++++---------------- spec/input/ssh_spec.rb | 15 +++++++-------- spec/node_spec.rb | 7 +++---- spec/nodes_spec.rb | 4 ++-- 4 files changed, 27 insertions(+), 30 deletions(-) (limited to 'spec') diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb index e676534..baa9a14 100644 --- a/spec/githubrepo_spec.rb +++ b/spec/githubrepo_spec.rb @@ -3,11 +3,11 @@ require 'rugged' require 'oxidized/hook/githubrepo' describe GithubRepo do - let(:credentials) { mock() } - let(:remote) { mock() } - let(:remotes) { mock() } - let(:repo_head) { mock() } - let(:repo) { mock() } + let(:credentials) { mock } + let(:remote) { mock } + let(:remotes) { mock } + let(:repo_head) { mock } + let(:repo) { mock } let(:gr) { GithubRepo.new } before do @@ -44,15 +44,15 @@ describe GithubRepo do gr.fetch_and_merge_remote(repo).must_equal nil end describe "when there is update considering conflicts" do - let(:merge_index) { mock() } - let(:their_branch) { mock() } + let(:merge_index) { mock } + let(:their_branch) { mock } before(:each) do - repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns({total_deltas: 1}) + repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(total_deltas: 1) their_branch.expects(:target_id).returns(1) repo_head.expects(:target_id).returns(2) repo.expects(:merge_commits).with(2, 1).returns(merge_index) - repo.expects(:branches).returns({"origin/master" => their_branch}) + repo.expects(:branches).returns("origin/master" => their_branch) end it "should not try merging when there's conflict" do @@ -70,12 +70,11 @@ describe GithubRepo do repo_head.expects(:target).returns("our_target") merge_index.expects(:write_tree).with(repo).returns("tree") merge_index.expects(:conflicts?).returns(false) - Rugged::Commit.expects(:create).with(repo, { - parents: ["our_target", "their_target"], - tree: "tree", - message: "Merge remote-tracking branch 'origin/master'", - update_ref: "HEAD" - }).returns(1) + Rugged::Commit.expects(:create).with(repo, + parents: ["our_target", "their_target"], + tree: "tree", + message: "Merge remote-tracking branch 'origin/master'", + update_ref: "HEAD").returns(1) gr.fetch_and_merge_remote(repo).must_equal 1 end end @@ -101,7 +100,7 @@ describe GithubRepo do Oxidized.config.output.git.repo = '/foo.git' remote.expects(:url).returns('https://github.com/username/foo.git') remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) - repo.expects(:remotes).returns({'origin' => remote}) + repo.expects(:remotes).returns('origin' => remote) Rugged::Repository.expects(:new).with('/foo.git').returns(repo) end diff --git a/spec/input/ssh_spec.rb b/spec/input/ssh_spec.rb index 7be9139..2d1f5ce 100644 --- a/spec/input/ssh_spec.rb +++ b/spec/input/ssh_spec.rb @@ -14,23 +14,22 @@ describe Oxidized::SSH do model: 'junos', username: 'alma', password: 'armud', - vars: {ssh_proxy: 'test.com'}) - + vars: { ssh_proxy: 'test.com' }) end describe "#connect" do it "should use proxy command when proxy host given" do ssh = Oxidized::SSH.new - model = mock() - model.expects(:cfg).returns({'ssh' => []}) + model = mock + model.expects(:cfg).returns('ssh' => []) @node.expects(:model).returns(model).at_least_once - proxy = mock() + proxy = mock Net::SSH::Proxy::Command.expects(:new).with("ssh test.com -W %h:%p").returns(proxy) - Net::SSH.expects(:start).with('93.184.216.34', 'alma', {:port => 22, :password => 'armud', :timeout => Oxidized.config.timeout, - :paranoid => Oxidized.config.input.ssh.secure, :auth_methods => ['none', 'publickey', 'password', 'keyboard-interactive'], - :number_of_password_prompts => 0, :proxy => proxy}) + Net::SSH.expects(:start).with('93.184.216.34', 'alma', :port => 22, :password => 'armud', :timeout => Oxidized.config.timeout, + :paranoid => Oxidized.config.input.ssh.secure, :auth_methods => ['none', 'publickey', 'password', 'keyboard-interactive'], + :number_of_password_prompts => 0, :proxy => proxy) ssh.instance_variable_set("@exec", true) ssh.connect(@node) diff --git a/spec/node_spec.rb b/spec/node_spec.rb index 829e05a..f769751 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -14,7 +14,6 @@ describe Oxidized::Node do username: 'alma', password: 'armud', prompt: 'test_prompt') - end describe '#new' do @@ -39,7 +38,7 @@ describe Oxidized::Node do it 'should fetch the configuration' do stub_oxidized_ssh - status, _ = @node.run + status, = @node.run status.must_equal :success end end @@ -52,9 +51,9 @@ describe Oxidized::Node do let(:group) { nil } let(:node) do - Oxidized::Node.new({ + Oxidized::Node.new( ip: '127.0.0.1', group: group, model: 'junos' - }) + ) end it 'when there are no groups' do diff --git a/spec/nodes_spec.rb b/spec/nodes_spec.rb index 6fa4b41..a801107 100644 --- a/spec/nodes_spec.rb +++ b/spec/nodes_spec.rb @@ -17,8 +17,8 @@ describe Oxidized::Nodes do Oxidized::Node.any_instance.stubs(:resolve_repo) Oxidized::Node.any_instance.stubs(:resolve_output) - @nodes_org = %w(ltt-pe1.hel kes2-rr1.tku tor-peer1.oul - hal-p2.tre sav-gr1-sw1.kuo psl-sec-pe1.hel).map { |e| Oxidized::Node.new(opts.merge(name: e)) } + @nodes_org = %w[ltt-pe1.hel kes2-rr1.tku tor-peer1.oul + hal-p2.tre sav-gr1-sw1.kuo psl-sec-pe1.hel].map { |e| Oxidized::Node.new(opts.merge(name: e)) } @node = @nodes_org.delete_at(0) @nodes = Oxidized::Nodes.new(nodes: @nodes_org.dup) end -- cgit v1.2.1 From 21e3d6490496573f25ef77fe8172766ac7d1a736 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sat, 21 Apr 2018 13:27:05 +0200 Subject: the great makeover - standardize layout, alignment, indentation --- spec/cli_spec.rb | 8 ++++---- spec/githubrepo_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index bf6058a..4ceb8ed 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -2,11 +2,11 @@ require 'spec_helper' require 'oxidized/cli' describe Oxidized::CLI do - before(:each) do - @original = ARGV - Oxidized.asetus = Asetus.new + before(:each) do + @original = ARGV + Oxidized.asetus = Asetus.new end - + after(:each) do ARGV.replace @original end diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb index baa9a14..67c99f0 100644 --- a/spec/githubrepo_spec.rb +++ b/spec/githubrepo_spec.rb @@ -70,7 +70,7 @@ describe GithubRepo do repo_head.expects(:target).returns("our_target") merge_index.expects(:write_tree).with(repo).returns("tree") merge_index.expects(:conflicts?).returns(false) - Rugged::Commit.expects(:create).with(repo, + Rugged::Commit.expects(:create).with(repo, parents: ["our_target", "their_target"], tree: "tree", message: "Merge remote-tracking branch 'origin/master'", -- cgit v1.2.1 From 82d67f2f337df5dbef8109fc67ddc9a86ba79bdc Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 22 Apr 2018 22:06:23 +0200 Subject: integrate codecov --- spec/spec_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2b49a6c..fc5167f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,11 @@ +require 'simplecov' +SimpleCov.start + +if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatter = SimpleCov::Formatter::Codecov +end + require 'minitest/autorun' require 'mocha/minitest' require 'oxidized' -- cgit v1.2.1 From 57348a626811688eb014d97d5aa401a10b3898bd Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 25 Apr 2018 16:56:20 +0200 Subject: move hook tests into own directory and regen rubocop todo --- spec/githubrepo_spec.rb | 170 ------------------------------------------- spec/hook/githubrepo_spec.rb | 170 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 170 deletions(-) delete mode 100644 spec/githubrepo_spec.rb create mode 100644 spec/hook/githubrepo_spec.rb (limited to 'spec') diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb deleted file mode 100644 index 67c99f0..0000000 --- a/spec/githubrepo_spec.rb +++ /dev/null @@ -1,170 +0,0 @@ -require 'spec_helper' -require 'rugged' -require 'oxidized/hook/githubrepo' - -describe GithubRepo do - let(:credentials) { mock } - let(:remote) { mock } - let(:remotes) { mock } - let(:repo_head) { mock } - let(:repo) { mock } - let(:gr) { GithubRepo.new } - - before do - Oxidized.asetus = Asetus.new - Oxidized.config.log = '/dev/null' - Oxidized.setup_logger - Oxidized.config.output.default = 'git' - end - - describe '#validate_cfg!' do - before do - gr.expects(:respond_to?).with(:validate_cfg!).returns(false) # `cfg=` call - end - - it 'raise a error when `remote_repo` is not configured' do - Oxidized.config.hooks.github_repo_hook = { type: 'githubrepo' } - gr.cfg = Oxidized.config.hooks.github_repo_hook - proc { gr.validate_cfg! }.must_raise(KeyError) - end - end - - describe "#fetch_and_merge_remote" do - before(:each) do - Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' - Proc.expects(:new).returns(credentials) - repo_head.expects(:name).returns('refs/heads/master') - gr.cfg = Oxidized.config.hooks.github_repo_hook - end - - it "should not try to merge when there is no update in remote branch" do - repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(Hash.new(0)) - repo.expects(:branches).never - repo.expects(:head).returns(repo_head) - gr.fetch_and_merge_remote(repo).must_equal nil - end - describe "when there is update considering conflicts" do - let(:merge_index) { mock } - let(:their_branch) { mock } - - before(:each) do - repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(total_deltas: 1) - their_branch.expects(:target_id).returns(1) - repo_head.expects(:target_id).returns(2) - repo.expects(:merge_commits).with(2, 1).returns(merge_index) - repo.expects(:branches).returns("origin/master" => their_branch) - end - - it "should not try merging when there's conflict" do - repo.expects(:head).twice.returns(repo_head) - their_branch.expects(:name).returns("origin/master") - merge_index.expects(:conflicts?).returns(true) - Rugged::Commit.expects(:create).never - gr.fetch_and_merge_remote(repo).must_equal nil - end - - it "should merge when there is no conflict" do - repo.expects(:head).times(3).returns(repo_head) - their_branch.expects(:target).returns("their_target") - their_branch.expects(:name).twice.returns("origin/master") - repo_head.expects(:target).returns("our_target") - merge_index.expects(:write_tree).with(repo).returns("tree") - merge_index.expects(:conflicts?).returns(false) - Rugged::Commit.expects(:create).with(repo, - parents: ["our_target", "their_target"], - tree: "tree", - message: "Merge remote-tracking branch 'origin/master'", - update_ref: "HEAD").returns(1) - gr.fetch_and_merge_remote(repo).must_equal 1 - end - end - end - - describe "#run_hook" do - let(:group) { nil } - let(:ctx) { OpenStruct.new(node: node) } - let(:node) do - Oxidized::Node.new(ip: '127.0.0.1', group: group, model: 'junos', output: 'git') - end - - before do - Proc.expects(:new).returns(credentials) - repo_head.expects(:name).twice.returns('refs/heads/master') - repo.expects(:head).twice.returns(repo_head) - repo.expects(:path).returns('/foo.git') - repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(Hash.new(0)) - end - - describe 'when there is only one repository and no groups' do - before do - Oxidized.config.output.git.repo = '/foo.git' - remote.expects(:url).returns('https://github.com/username/foo.git') - remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) - repo.expects(:remotes).returns('origin' => remote) - Rugged::Repository.expects(:new).with('/foo.git').returns(repo) - end - - it "will push to the remote repository using https" do - Oxidized.config.hooks.github_repo_hook.remote_repo = 'https://github.com/username/foo.git' - Oxidized.config.hooks.github_repo_hook.username = 'username' - Oxidized.config.hooks.github_repo_hook.password = 'password' - Proc.expects(:new).returns(credentials) - gr.cfg = Oxidized.config.hooks.github_repo_hook - gr.run_hook(ctx).must_equal true - end - - it "will push to the remote repository using ssh" do - Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' - Proc.expects(:new).returns(credentials) - gr.cfg = Oxidized.config.hooks.github_repo_hook - gr.run_hook(ctx).must_equal true - end - end - - describe "when there are groups" do - let(:group) { 'ggrroouupp' } - - before do - Proc.expects(:new).returns(credentials) - Rugged::Repository.expects(:new).with(repository).returns(repo) - - repo.expects(:remotes).twice.returns(remotes) - remotes.expects(:[]).with('origin').returns(nil) - remotes.expects(:create).with('origin', create_remote).returns(remote) - remote.expects(:url).returns('url') - remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) - end - - describe 'and there are several repositories' do - let(:create_remote) { 'ggrroouupp#remote_repo' } - let(:repository) { '/ggrroouupp.git' } - - before do - Oxidized.config.output.git.repo.ggrroouupp = repository - Oxidized.config.hooks.github_repo_hook.remote_repo.ggrroouupp = 'ggrroouupp#remote_repo' - end - - it 'will push to the node group repository' do - gr.cfg = Oxidized.config.hooks.github_repo_hook - gr.run_hook(ctx).must_equal true - end - end - - describe 'and has a single repository' do - let(:create_remote) { 'github_repo_hook#remote_repo' } - let(:repository) { '/foo.git' } - - before do - Oxidized.config.output.git.repo = repository - Oxidized.config.hooks.github_repo_hook.remote_repo = 'github_repo_hook#remote_repo' - Oxidized.config.output.git.single_repo = true - end - - it 'will push to the correct repository' do - gr.cfg = Oxidized.config.hooks.github_repo_hook - gr.run_hook(ctx).must_equal true - end - end - end - end -end diff --git a/spec/hook/githubrepo_spec.rb b/spec/hook/githubrepo_spec.rb new file mode 100644 index 0000000..67c99f0 --- /dev/null +++ b/spec/hook/githubrepo_spec.rb @@ -0,0 +1,170 @@ +require 'spec_helper' +require 'rugged' +require 'oxidized/hook/githubrepo' + +describe GithubRepo do + let(:credentials) { mock } + let(:remote) { mock } + let(:remotes) { mock } + let(:repo_head) { mock } + let(:repo) { mock } + let(:gr) { GithubRepo.new } + + before do + Oxidized.asetus = Asetus.new + Oxidized.config.log = '/dev/null' + Oxidized.setup_logger + Oxidized.config.output.default = 'git' + end + + describe '#validate_cfg!' do + before do + gr.expects(:respond_to?).with(:validate_cfg!).returns(false) # `cfg=` call + end + + it 'raise a error when `remote_repo` is not configured' do + Oxidized.config.hooks.github_repo_hook = { type: 'githubrepo' } + gr.cfg = Oxidized.config.hooks.github_repo_hook + proc { gr.validate_cfg! }.must_raise(KeyError) + end + end + + describe "#fetch_and_merge_remote" do + before(:each) do + Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' + Proc.expects(:new).returns(credentials) + repo_head.expects(:name).returns('refs/heads/master') + gr.cfg = Oxidized.config.hooks.github_repo_hook + end + + it "should not try to merge when there is no update in remote branch" do + repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(Hash.new(0)) + repo.expects(:branches).never + repo.expects(:head).returns(repo_head) + gr.fetch_and_merge_remote(repo).must_equal nil + end + describe "when there is update considering conflicts" do + let(:merge_index) { mock } + let(:their_branch) { mock } + + before(:each) do + repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(total_deltas: 1) + their_branch.expects(:target_id).returns(1) + repo_head.expects(:target_id).returns(2) + repo.expects(:merge_commits).with(2, 1).returns(merge_index) + repo.expects(:branches).returns("origin/master" => their_branch) + end + + it "should not try merging when there's conflict" do + repo.expects(:head).twice.returns(repo_head) + their_branch.expects(:name).returns("origin/master") + merge_index.expects(:conflicts?).returns(true) + Rugged::Commit.expects(:create).never + gr.fetch_and_merge_remote(repo).must_equal nil + end + + it "should merge when there is no conflict" do + repo.expects(:head).times(3).returns(repo_head) + their_branch.expects(:target).returns("their_target") + their_branch.expects(:name).twice.returns("origin/master") + repo_head.expects(:target).returns("our_target") + merge_index.expects(:write_tree).with(repo).returns("tree") + merge_index.expects(:conflicts?).returns(false) + Rugged::Commit.expects(:create).with(repo, + parents: ["our_target", "their_target"], + tree: "tree", + message: "Merge remote-tracking branch 'origin/master'", + update_ref: "HEAD").returns(1) + gr.fetch_and_merge_remote(repo).must_equal 1 + end + end + end + + describe "#run_hook" do + let(:group) { nil } + let(:ctx) { OpenStruct.new(node: node) } + let(:node) do + Oxidized::Node.new(ip: '127.0.0.1', group: group, model: 'junos', output: 'git') + end + + before do + Proc.expects(:new).returns(credentials) + repo_head.expects(:name).twice.returns('refs/heads/master') + repo.expects(:head).twice.returns(repo_head) + repo.expects(:path).returns('/foo.git') + repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(Hash.new(0)) + end + + describe 'when there is only one repository and no groups' do + before do + Oxidized.config.output.git.repo = '/foo.git' + remote.expects(:url).returns('https://github.com/username/foo.git') + remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) + repo.expects(:remotes).returns('origin' => remote) + Rugged::Repository.expects(:new).with('/foo.git').returns(repo) + end + + it "will push to the remote repository using https" do + Oxidized.config.hooks.github_repo_hook.remote_repo = 'https://github.com/username/foo.git' + Oxidized.config.hooks.github_repo_hook.username = 'username' + Oxidized.config.hooks.github_repo_hook.password = 'password' + Proc.expects(:new).returns(credentials) + gr.cfg = Oxidized.config.hooks.github_repo_hook + gr.run_hook(ctx).must_equal true + end + + it "will push to the remote repository using ssh" do + Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' + Proc.expects(:new).returns(credentials) + gr.cfg = Oxidized.config.hooks.github_repo_hook + gr.run_hook(ctx).must_equal true + end + end + + describe "when there are groups" do + let(:group) { 'ggrroouupp' } + + before do + Proc.expects(:new).returns(credentials) + Rugged::Repository.expects(:new).with(repository).returns(repo) + + repo.expects(:remotes).twice.returns(remotes) + remotes.expects(:[]).with('origin').returns(nil) + remotes.expects(:create).with('origin', create_remote).returns(remote) + remote.expects(:url).returns('url') + remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) + end + + describe 'and there are several repositories' do + let(:create_remote) { 'ggrroouupp#remote_repo' } + let(:repository) { '/ggrroouupp.git' } + + before do + Oxidized.config.output.git.repo.ggrroouupp = repository + Oxidized.config.hooks.github_repo_hook.remote_repo.ggrroouupp = 'ggrroouupp#remote_repo' + end + + it 'will push to the node group repository' do + gr.cfg = Oxidized.config.hooks.github_repo_hook + gr.run_hook(ctx).must_equal true + end + end + + describe 'and has a single repository' do + let(:create_remote) { 'github_repo_hook#remote_repo' } + let(:repository) { '/foo.git' } + + before do + Oxidized.config.output.git.repo = repository + Oxidized.config.hooks.github_repo_hook.remote_repo = 'github_repo_hook#remote_repo' + Oxidized.config.output.git.single_repo = true + end + + it 'will push to the correct repository' do + gr.cfg = Oxidized.config.hooks.github_repo_hook + gr.run_hook(ctx).must_equal true + end + end + end + end +end -- cgit v1.2.1 From 75765bedae8a8511260d43ec7f46edc994899c7c Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 25 Apr 2018 19:06:19 +0200 Subject: fix cli_spec.rb to reflect new version output --- spec/cli_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 4ceb8ed..8b9b792 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -21,7 +21,7 @@ describe Oxidized::CLI do File.expects(:expand_path) Kernel.expects(:exit) - assert_output("#{Oxidized::VERSION}\n") { Oxidized::CLI.new } + assert_output("#{Oxidized::VERSION_FULL}\n") { Oxidized::CLI.new } end end end -- cgit v1.2.1 From cf770c557fc5d55786b56a31e389ff6d629315b4 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Fri, 27 Apr 2018 11:32:47 +0300 Subject: Add SSH keepalive Closes #1276 --- spec/input/ssh_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/input/ssh_spec.rb b/spec/input/ssh_spec.rb index 2d1f5ce..9e08cea 100644 --- a/spec/input/ssh_spec.rb +++ b/spec/input/ssh_spec.rb @@ -27,9 +27,14 @@ describe Oxidized::SSH do proxy = mock Net::SSH::Proxy::Command.expects(:new).with("ssh test.com -W %h:%p").returns(proxy) - Net::SSH.expects(:start).with('93.184.216.34', 'alma', :port => 22, :password => 'armud', :timeout => Oxidized.config.timeout, - :paranoid => Oxidized.config.input.ssh.secure, :auth_methods => ['none', 'publickey', 'password', 'keyboard-interactive'], - :number_of_password_prompts => 0, :proxy => proxy) + Net::SSH.expects(:start).with('93.184.216.34', 'alma', port: 22, + timeout: Oxidized.config.timeout, + paranoid: Oxidized.config.input.ssh.secure, + keepalive: true, + proxy: proxy, + password: 'armud', + number_of_password_prompts: 0, + auth_methods: ['none', 'publickey', 'password', 'keyboard-interactive']) ssh.instance_variable_set("@exec", true) ssh.connect(@node) -- cgit v1.2.1