Skip to content

Commit

Permalink
[test] fixed agent validation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Mar 27, 2015
1 parent 438afc4 commit 9e58c96
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def private_key
FactoryGirl.define do

sequence(:uuid) { |n| "uuid-#{n}" }
sequence(:pubkey) { |n| }
sequence(:username) { |n| "chetan#{n}" }
sequence(:email_id) { |n| "test#{n}@fw2.net" }
sequence(:tenant_name) { |n| "foo.org #{n}" }
Expand Down
6 changes: 6 additions & 0 deletions test/setup/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def create_bundle(path)
bundle
end

def create_agent_without_validation
agent = FactoryGirl.build(:agent)
agent.save(:validate => false)
agent
end

end

module Models
Expand Down
6 changes: 6 additions & 0 deletions test/setup/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def sign_with_agent
ApiAuth.sign!(@request, @agent.access_key, @agent.secret_key)
end

def create_agent_without_validation
agent = FactoryGirl.build(:agent)
agent.save(:validate => false)
agent
end

end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_add_check_with_empty_args
end

def test_add_check_with_diff_agent
agent2 = FactoryGirl.create(:agent)
agent2 = create_agent_without_validation
args = {:host_id => @agent.host.id, :command_id => @command.id, :runhost_id => agent2.host.id}
post :create, args
assert_response 200
Expand Down
2 changes: 1 addition & 1 deletion test/unit/controllers/rest/models/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_index
sign_with_agent

# add another host to make sure we get both back
h = FactoryGirl.create(:agent).host
h = create_agent_without_validation.host
h.org_id = @host.org.id
h.save!

Expand Down
4 changes: 2 additions & 2 deletions test/unit/models/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_search_by_metadata
host.add_metadata("foo", "bar")

# create an extra agent/host
FactoryGirl.create(:agent).host.tap { |h| h.org = host.org; h.save }
create_agent_without_validation.host.tap { |h| h.org = host.org; h.save }

hosts = Host.search("foo=bar", user)
assert_equal 1, hosts.size
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_search_inactive

def test_for_user
h = FactoryGirl.create(:agent).host
h2 = FactoryGirl.create(:agent).host
h2 = create_agent_without_validation.host
u = FactoryGirl.create(:user)
u.org = h.org
u.save
Expand Down
6 changes: 2 additions & 4 deletions test/unit/modules/monitoring_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ def test_update_check_config
}.
to_return(:status => 200, :body => cmd_res_json())

check = FactoryGirl.create(:check)

Provisioning.any_instance.expects(:provision).once.with { |agent, cmd|
agent == check.agent and cmd.kind_of?(Array) and cmd.size == 1 and cmd.first.bundle == check.command.bundle.path
agent == @check.agent and cmd.kind_of?(Array) and cmd.size == 1 and cmd.first.bundle == @check.command.bundle.path
}

ret = Bixby::Monitoring.new.update_check_config(check.agent)
ret = Bixby::Monitoring.new.update_check_config(@check.agent)

assert_requested(stub)
assert_kind_of CommandResponse, ret
Expand Down

0 comments on commit 9e58c96

Please sign in to comment.