spec/unit/action/runner_spec.rb in r10k-3.7.0 vs spec/unit/action/runner_spec.rb in r10k-3.8.0
- old
+ new
@@ -8,15 +8,16 @@
let(:action_class) do
Class.new do
attr_reader :opts
attr_reader :argv
+ attr_reader :settings
def initialize(opts, argv, settings = {})
@opts = opts
@argv = argv
- @settings = {}
+ @settings = settings
end
def call
@argv.map(&:upcase)
end
@@ -165,9 +166,55 @@
end
it "does not modify the loglevel if :loglevel is not provided" do
expect(R10K::Logging).to_not receive(:level=)
runner.call
+ end
+ end
+
+ describe "configuring git credentials" do
+ it 'errors if both token and key paths are passed' do
+ runner = described_class.new({ 'oauth-token': '/nonexistent',
+ 'private-key': '/also/fake' }, %w[args yes], action_class)
+ expect{ runner.call }.to raise_error(R10K::Error, /Cannot specify both/)
+ end
+
+ it 'saves the sshkey path in settings hash' do
+ runner = described_class.new({ 'private-key': '/my/ssh/key' }, %w[args yes], action_class)
+ runner.call
+ expect(runner.instance.settings[:git][:private_key]).to eq('/my/ssh/key')
+ end
+
+ it 'overrides per-repo sshkey in settings hash' do
+ runner = described_class.new({ config: "spec/fixtures/unit/action/r10k_creds.yaml",
+ 'private-key': '/my/ssh/key' },
+ %w[args yes],
+ action_class)
+ runner.call
+ expect(runner.instance.settings[:git][:private_key]).to eq('/my/ssh/key')
+ expect(runner.instance.settings[:git][:repositories].count).to eq(2)
+ runner.instance.settings[:git][:repositories].each do |repo_settings|
+ expect(repo_settings[:private_key]).to eq('/my/ssh/key')
+ end
+ end
+
+ it 'saves the token path in settings hash' do
+ runner = described_class.new({ 'oauth-token': '/my/token/path' }, %w[args yes], action_class)
+ runner.call
+ expect(runner.instance.settings[:git][:oauth_token]).to eq('/my/token/path')
+ end
+
+ it 'overrides per-repo oauth token in settings hash' do
+ runner = described_class.new({ config: "spec/fixtures/unit/action/r10k_creds.yaml",
+ 'oauth-token': '/my/token' },
+ %w[args yes],
+ action_class)
+ runner.call
+ expect(runner.instance.settings[:git][:oauth_token]).to eq('/my/token')
+ expect(runner.instance.settings[:git][:repositories].count).to eq(2)
+ runner.instance.settings[:git][:repositories].each do |repo_settings|
+ expect(repo_settings[:oauth_token]).to eq('/my/token')
+ end
end
end
describe "configuration authorization" do
context "when license is not present" do