spec/unit/action/deploy/module_spec.rb in r10k-3.10.0 vs spec/unit/action/deploy/module_spec.rb in r10k-3.11.0

- old
+ new

@@ -39,10 +39,26 @@ end it 'can accept a token option' do described_class.new({ 'oauth-token': '/nonexistent' }, [], {}) end + + it 'can accept an app id option' do + described_class.new({ 'github-app-id': '/nonexistent' }, [], {}) + end + + it 'can accept a ttl option' do + described_class.new({ 'github-app-ttl': '/nonexistent' }, [], {}) + end + + it 'can accept a ssl private key option' do + described_class.new({ 'github-app-key': '/nonexistent' }, [], {}) + end + + it 'can accept a exclude-spec option' do + described_class.new({ :'exclude-spec' => true }, [], {}) + end end describe "with no-force" do subject { described_class.new({ config: "/some/nonexistent/path", :'no-force' => true}, [], {}) } @@ -175,10 +191,37 @@ it 'sets token_path' do expect(subject.instance_variable_get(:@oauth_token)).to eq('/nonexistent') end end + describe 'with github-app-id' do + + subject { described_class.new({ config: '/some/nonexistent/path', 'github-app-id': '/nonexistent' }, [], {}) } + + it 'sets github-app-id' do + expect(subject.instance_variable_get(:@github_app_id)).to eq('/nonexistent') + end + end + + describe 'with github-app-key' do + + subject { described_class.new({ config: '/some/nonexistent/path', 'github-app-key': '/nonexistent' }, [], {}) } + + it 'sets github-app-key' do + expect(subject.instance_variable_get(:@github_app_key)).to eq('/nonexistent') + end + end + + describe 'with github-app-ttl' do + + subject { described_class.new({ config: '/some/nonexistent/path', 'github-app-ttl': '/nonexistent' }, [], {}) } + + it 'sets github-app-ttl' do + expect(subject.instance_variable_get(:@github_app_ttl)).to eq('/nonexistent') + end + end + describe 'with modules' do subject { described_class.new({ config: '/some/nonexistent/path' }, ['mod1', 'mod2'], {}) } let(:cache) { instance_double("R10K::Git::Cache", 'sanitized_dirname' => 'foo', 'cached?' => true, 'sync' => true) } @@ -302,9 +345,144 @@ expect(repo).to receive(:sync).once expect(subject.logger).to receive(:debug1).with(/Updating modules.*in environment.*first/i) expect(subject.logger).to receive(:debug1).with(/skipping environment.*second/i) subject.call + end + end + + + describe "postrun" do + let(:mock_config) do + R10K::Deployment::MockConfig.new( + :sources => { + :control => { + :type => :mock, + :basedir => '/some/nonexistent/path/control', + :environments => %w[first second third], + } + } + ) + end + + context "basic postrun hook" do + let(:settings) { { postrun: ["/path/to/executable", "arg1", "arg2"] } } + let(:deployment) { R10K::Deployment.new(mock_config.merge(settings)) } + + before do + expect(R10K::Deployment).to receive(:new).and_return(deployment) + end + + subject do + described_class.new({config: "/some/nonexistent/path" }, + ['mod1'], settings) + end + + it "is passed to Subprocess" do + mock_subprocess = double + allow(mock_subprocess).to receive(:logger=) + expect(mock_subprocess).to receive(:execute) + + expect(R10K::Util::Subprocess).to receive(:new). + with(["/path/to/executable", "arg1", "arg2"]). + and_return(mock_subprocess) + + expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block| + modified = subject.instance_variable_get(:@modified_envs) << environment + subject.instance_variable_set(:modified_envs, modified) + end.exactly(3).times + + subject.call + end + end + + context "supports environments" do + context "with one environment" do + let(:settings) { { postrun: ["/generate/types/wrapper", "$modifiedenvs"] } } + let(:deployment) { R10K::Deployment.new(mock_config.merge(settings)) } + + before do + expect(R10K::Deployment).to receive(:new).and_return(deployment) + end + + subject do + described_class.new({ config: '/some/nonexistent/path', + environment: 'first' }, + ['mod1'], settings) + end + + it "properly substitutes the environment" do + mock_subprocess = double + allow(mock_subprocess).to receive(:logger=) + expect(mock_subprocess).to receive(:execute) + + mock_mod = double('mock_mod', name: 'mod1') + + expect(R10K::Util::Subprocess).to receive(:new). + with(["/generate/types/wrapper", "first"]). + and_return(mock_subprocess) + + expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block| + if environment.name == 'first' + expect(environment).to receive(:deploy).and_return(true) + expect(environment).to receive(:modules).and_return([mock_mod]) + end + original.call(environment, &block) + end.exactly(3).times + + subject.call + end + end + + context "with all environments" do + let(:settings) { { postrun: ["/generate/types/wrapper", "$modifiedenvs"] } } + let(:deployment) { R10K::Deployment.new(mock_config.merge(settings)) } + + before do + expect(R10K::Deployment).to receive(:new).and_return(deployment) + end + + subject do + described_class.new({ config: '/some/nonexistent/path' }, + ['mod1'], settings) + end + + it "properly substitutes the environment where modules were deployed" do + mock_subprocess = double + allow(mock_subprocess).to receive(:logger=) + expect(mock_subprocess).to receive(:execute) + + expect(R10K::Util::Subprocess).to receive(:new). + with(["/generate/types/wrapper", "first third"]). + and_return(mock_subprocess) + + mock_mod = double('mock_mod', name: 'mod1') + + expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block| + expect(environment).to receive(:deploy).and_return(true) + if ['first', 'third'].include?(environment.name) + expect(environment).to receive(:modules).and_return([mock_mod]) + end + original.call(environment, &block) + end.exactly(3).times + + subject.call + end + + it "does not execute the command if no envs had the module" do + expect(R10K::Util::Subprocess).not_to receive(:new) + + mock_mod2 = double('mock_mod', name: 'mod2') + expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block| + expect(environment).to receive(:deploy).and_return(true) + # Envs have a different module than the one we asked to deploy + expect(environment).to receive(:modules).and_return([mock_mod2]) + original.call(environment, &block) + end.exactly(3).times + + subject.call + end + end end end end