|
| 1 | +require 'spec_helper' |
| 2 | +require 'puppet/util/node_groups' |
| 3 | +require 'webmock/rspec' |
| 4 | + |
| 5 | +describe 'node_groups' do |
| 6 | + unless Puppet.features.puppetclassify? |
| 7 | + skip "puppetclassify gem not installed" |
| 8 | + else |
| 9 | + describe 'input validation' do |
| 10 | + it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(ArgumentError, /Function accepts a single String/i) } |
| 11 | + it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, /Function accepts a single String/i) } |
| 12 | + end |
| 13 | + |
| 14 | + groups_response = <<-EOS |
| 15 | + [ |
| 16 | + { |
| 17 | + "classes": {}, |
| 18 | + "environment": "production", |
| 19 | + "environment_trumps": false, |
| 20 | + "id": "00000000-0000-4000-8000-000000000000", |
| 21 | + "name": "All Nodes", |
| 22 | + "parent": "00000000-0000-4000-8000-000000000000", |
| 23 | + "rule": [ |
| 24 | + "and", |
| 25 | + [ |
| 26 | + "~", |
| 27 | + "name", |
| 28 | + ".*" |
| 29 | + ] |
| 30 | + ], |
| 31 | + "variables": {} |
| 32 | + }, |
| 33 | + { |
| 34 | + "classes": {}, |
| 35 | + "environment": "production", |
| 36 | + "environment_trumps": false, |
| 37 | + "id": "7233f964-951e-4a7f-88ea-72676ed3104d", |
| 38 | + "name": "Production environment", |
| 39 | + "parent": "00000000-0000-4000-8000-000000000000", |
| 40 | + "rule": [ |
| 41 | + "and", |
| 42 | + [ |
| 43 | + "~", |
| 44 | + "name", |
| 45 | + ".*" |
| 46 | + ] |
| 47 | + ], |
| 48 | + "variables": {} |
| 49 | + } |
| 50 | + ] |
| 51 | + EOS |
| 52 | + |
| 53 | + hashified = { |
| 54 | + 'All Nodes' => { |
| 55 | + 'classes' => {}, |
| 56 | + 'environment' => 'production', |
| 57 | + 'environment_trumps' => false, |
| 58 | + 'id' => '00000000-0000-4000-8000-000000000000', |
| 59 | + 'name' => 'All Nodes', |
| 60 | + 'parent' => '00000000-0000-4000-8000-000000000000', |
| 61 | + 'rule' => ['and', ['~', 'name', '.*']], |
| 62 | + 'variables' => {}, |
| 63 | + }, |
| 64 | + 'Production environment' => { |
| 65 | + 'classes' => {}, |
| 66 | + 'environment' => 'production', |
| 67 | + 'environment_trumps' => false, |
| 68 | + 'id' => '7233f964-951e-4a7f-88ea-72676ed3104d', |
| 69 | + 'name' => 'Production environment', |
| 70 | + 'parent' => '00000000-0000-4000-8000-000000000000', |
| 71 | + 'rule' => ['and', ['~', 'name', '.*']], |
| 72 | + 'variables' => {}, |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + before do |
| 77 | + YAML.stubs(:load_file).returns({ |
| 78 | + 'server' => 'stubserver', |
| 79 | + 'port' => '8080', |
| 80 | + }) |
| 81 | + stub_request( |
| 82 | + :get, |
| 83 | + 'https://stubserver:8080/classifier-api/v1/groups', |
| 84 | + ).to_return( |
| 85 | + :status => 200, |
| 86 | + :body => groups_response |
| 87 | + ) |
| 88 | + end |
| 89 | + |
| 90 | + describe 'without an argument' do |
| 91 | + it { should run.with_params().and_return(hashified) } |
| 92 | + end |
| 93 | + |
| 94 | + describe 'with 1 String argument' do |
| 95 | + it { should run.with_params('All Nodes').and_return({ 'All Nodes' => hashified['All Nodes']}) } |
| 96 | + end |
| 97 | + end |
| 98 | +end |
0 commit comments