|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Fastlane::Actions::BuildkiteMetadataAction do |
| 4 | + it 'calls the right command to set a single metadata' do |
| 5 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'set', 'foo', 'bar') |
| 6 | + |
| 7 | + res = run_described_fastlane_action(set: { foo: 'bar' }) |
| 8 | + expect(res).to be_nil |
| 9 | + end |
| 10 | + |
| 11 | + it 'calls the commands as many times as necessary when we want to set multiple metadata at once' do |
| 12 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'set', 'key1', 'value1') |
| 13 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'set', 'key2', 'value2') |
| 14 | + |
| 15 | + metadata = { |
| 16 | + key1: 'value1', |
| 17 | + key2: 'value2' |
| 18 | + } |
| 19 | + run_described_fastlane_action(set: metadata) |
| 20 | + end |
| 21 | + |
| 22 | + it 'calls the right command to get the value of metadata, and returns the right value' do |
| 23 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'get', 'foo') |
| 24 | + allow(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'get', 'foo').and_return('foo value') |
| 25 | + |
| 26 | + res = run_described_fastlane_action(get: 'foo') |
| 27 | + expect(res).to eq('foo value') |
| 28 | + end |
| 29 | + |
| 30 | + it 'allows both setting and getting metadata in the same call' do |
| 31 | + # Might not be the main way we intend to use this action… but it's still supported. |
| 32 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'set', 'key1', 'value1') |
| 33 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'set', 'key2', 'value2') |
| 34 | + expect(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'get', 'key3') |
| 35 | + allow(Fastlane::Action).to receive(:sh).with('buildkite-agent', 'meta-data', 'get', 'key3').and_return('value3') |
| 36 | + |
| 37 | + new_metadata = { |
| 38 | + key1: 'value1', |
| 39 | + key2: 'value2' |
| 40 | + } |
| 41 | + res = run_described_fastlane_action(set: new_metadata, get: 'key3') |
| 42 | + |
| 43 | + expect(res).to eq('value3') |
| 44 | + end |
| 45 | +end |
0 commit comments