diff options
-rw-r--r-- | lib/gitlab_keys.rb | 2 | ||||
-rw-r--r-- | spec/gitlab_keys_spec.rb | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index 0600a18..85ca797 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -99,7 +99,7 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength matches = /^command=\".+?\s+(.+?)\".+?(?:ssh|ecdsa)-.*?\s(.+)\s*.*\n*$/.match(line) keys << "#{matches[1]} #{matches[2]}\n" unless matches.nil? end - keys + puts keys end def list_key_ids diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb index f86d00d..86128f6 100644 --- a/spec/gitlab_keys_spec.rb +++ b/spec/gitlab_keys_spec.rb @@ -95,16 +95,20 @@ describe GitlabKeys do end end - describe :list_keys do - let(:gitlab_keys) do - build_gitlab_keys('add-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') + describe ':list_keys' do + let(:gitlab_keys) { build_gitlab_keys('list_keys') } + let(:key_data) { "%s\n%s\n" % [described_class.key_line('key-741', 'ssh-rsa AAAAB3NzaDAxx2E'), described_class.key_line('key-742', 'ssh-rsa AAAAB3NzaDAxx2E')] } + let(:key_output) { "key-741 AAAAB3NzaDAxx2E\nkey-742 AAAAB3NzaDAxx2E\n" } + + before do + create_authorized_keys_fixture( + existing_content: + key_data + ) end - it 'adds a key and lists it' do - create_authorized_keys_fixture - gitlab_keys.send :add_key - auth_line1 = 'key-741 AAAAB3NzaDAxx2E' - expect(gitlab_keys.send(:list_keys)).to eq("#{auth_line1}\n") + it 'outputs the keys with IDs, separated by newlines' do + expect { gitlab_keys.send(:list_keys) }.to output(key_output).to_stdout end end |