|
52 | 52 | end |
53 | 53 |
|
54 | 54 | context 'when show action is called' do |
55 | | - let(:expected) { "{\n \"filesystems\": \"apfs,autofs,devfs\",\n \"macaddress\": \"64:52:11:22:03:25\"\n}\n" } |
| 55 | + let(:expected) { <<~END } |
| 56 | + { |
| 57 | + "filesystems": "apfs,autofs,devfs", |
| 58 | + "macaddress": "64:52:11:22:03:25" |
| 59 | + } |
| 60 | + END |
56 | 61 |
|
57 | 62 | before :each do |
58 | 63 | Puppet::Node::Facts.indirection.terminus_class = :facter |
|
64 | 69 | expect { |
65 | 70 | app.run |
66 | 71 | }.to exit_with(0) |
67 | | - .and output(expected).to_stdout |
| 72 | + .and output(expected).to_stdout |
| 73 | + end |
| 74 | + |
| 75 | + it 'displays a single fact value' do |
| 76 | + app.command_line.args << 'filesystems' << '--value-only' |
| 77 | + expect { |
| 78 | + app.run |
| 79 | + }.to exit_with(0) |
| 80 | + .and output("apfs,autofs,devfs\n").to_stdout |
| 81 | + end |
| 82 | + |
| 83 | + it "warns and ignores value-only when multiple fact names are specified" do |
| 84 | + app.command_line.args << 'filesystems' << 'macaddress' << '--value-only' |
| 85 | + expect { |
| 86 | + app.run |
| 87 | + }.to exit_with(0) |
| 88 | + .and output(expected).to_stdout |
| 89 | + .and output(/it can only be used when querying for a single fact/).to_stderr |
| 90 | + end |
| 91 | + |
| 92 | + { |
| 93 | + "type_hash" => [{'a' => 2}, "{\n \"a\": 2\n}"], |
| 94 | + "type_array" => [[], "[\n\n]"], |
| 95 | + "type_string" => ["str", "str"], |
| 96 | + "type_int" => [1, "1"], |
| 97 | + "type_float" => [1.0, "1.0"], |
| 98 | + "type_true" => [true, "true"], |
| 99 | + "type_false" => [false, "false"], |
| 100 | + "type_nil" => [nil, ""], |
| 101 | + "type_sym" => [:sym, "sym"] |
| 102 | + }.each_pair do |name, values| |
| 103 | + it "renders '#{name}' as '#{values.last}'" do |
| 104 | + fact_value = values.first |
| 105 | + fact_output = values.last |
| 106 | + |
| 107 | + allow(Facter).to receive(:resolve).and_return({name => fact_value}) |
| 108 | + |
| 109 | + app.command_line.args << name << '--value-only' |
| 110 | + expect { |
| 111 | + app.run |
| 112 | + }.to exit_with(0) |
| 113 | + .and output("#{fact_output}\n").to_stdout |
| 114 | + end |
68 | 115 | end |
69 | 116 | end |
70 | 117 |
|
71 | 118 | context 'when default action is called' do |
72 | | - let(:expected) { "---\nfilesystems: apfs,autofs,devfs\nmacaddress: 64:52:11:22:03:25\n" } |
| 119 | + let(:expected) { <<~END } |
| 120 | + --- |
| 121 | + filesystems: apfs,autofs,devfs |
| 122 | + macaddress: 64:52:11:22:03:25 |
| 123 | + END |
73 | 124 |
|
74 | 125 | before :each do |
75 | 126 | Puppet::Node::Facts.indirection.terminus_class = :facter |
|
81 | 132 | expect { |
82 | 133 | app.run |
83 | 134 | }.to exit_with(0) |
84 | | - .and output(expected).to_stdout |
| 135 | + .and output(expected).to_stdout |
85 | 136 | expect(app.action.name).to eq(:show) |
86 | 137 | end |
87 | 138 | end |
|
0 commit comments