spec/command/ldapsync_spec.rb in conjur-cli-5.2.5 vs spec/command/ldapsync_spec.rb in conjur-cli-5.3.0

- old
+ new

@@ -20,11 +20,82 @@ 'ldap-sync/source' => '192.168.99.100:389', 'ldap-sync/upstream-dn' => 'cn=Guest,dc=example,dc=org', } ].to_yaml } - describe_command 'ldap-sync now -f text' do + + + context 'when testing ldap-sync jobs commands' do + let(:jobs){ + [ + Conjur::LdapSyncJob.new(api, :id => 'job-1', :type => 'sync', :state => 'running', :exclusive => true), + Conjur::LdapSyncJob.new(api, :id => 'job-2', :type => 'connect', :state => 'success', :exclusive => false) + ] + } + + before do + expect_any_instance_of(Conjur::API).to receive(:ldap_sync_jobs).and_return jobs + end + + describe_command 'ldap-sync jobs list' do + it 'prints the jobs as json' do + expect { invoke }.to write(JSON.pretty_generate jobs.map(&:as_json)) + end + end + + describe_command 'ldap-sync jobs list -i' do + it 'prints the job ids only' do + expect { invoke }.to write(JSON.pretty_generate jobs.map(&:id)) + end + end + + describe_command 'ldap-sync jobs list -f pretty' do + + it 'prints the jobs in a fancy table' do + expect{ invoke }.to write /ID\s*|\s*TYPE\s*|\s*STATE\s*|\s*EXCLUSIVE.*? +job-1\s*|\s*sync\s*|\s*running\s*|\s*true +job-2\s*|\s*connect\s*|\s*success\s*|\s*false/x + end + end + + + describe_command 'ldap-sync jobs delete job-2' do + let(:victim){ jobs[1] } + it 'deletes the job' do + expect(victim).to receive(:delete) + invoke + end + end + + describe_command 'ldap-sync jobs delete no-such-job' do + it 'fails with a sensible error message' do + expect{ invoke }.to raise_exception(/No job found with ID 'no-such-job'/) + end + end + + describe_command 'ldap-sync jobs show job-1' do + let(:victim){ jobs[0] } + it 'prints the values passed to output' do + expect(victim).to receive(:output) do |&block| + block.call({foo: 'bar'}) + block.call({spam: 'eggs'}) + end + + expect{invoke}.to write(<<EOS) +{ + "foo": "bar" +} +{ + "spam": "eggs" +} +EOS + + end + end + end + + describe_command 'ldap-sync now --no-detach -f text' do before { expect_any_instance_of(Conjur::API).to receive(:ldap_sync_now).and_return json_response } it 'prints out diagnostic events' do expect { invoke }.to write([ timestamp, "info", "Performing sync" ].join("\t")) @@ -32,21 +103,22 @@ it 'prints out actions as text' do expect { invoke }.to write("user 'Guest'\ngroup 'Domain Computers'") end end - describe_command 'ldap-sync now -f yaml' do + describe_command 'ldap-sync now --no-detach -f yaml' do it 'prints out actions as unparsed yaml' do expect_any_instance_of(Conjur::API).to receive(:ldap_sync_now).and_return yaml_response expect { invoke }.to write(yaml_response) end end context 'when testing dry-run' do + let (:detach) { true } before do expect_any_instance_of(Conjur::API).to receive(:ldap_sync_now) - .with('default', 'application/json', dry_run) + .with(:config_name => 'default', :format => 'application/json', :dry_run => dry_run, :detach_job => detach) .and_return json_response end describe_command 'ldap-sync now' do let(:dry_run) { false } @@ -62,9 +134,10 @@ end end describe_command 'ldap-sync now --dry-run' do let(:dry_run) { true } + let(:detach) { false } it 'passes truthy dry-run value' do invoke end end end