require 'support/integration_helper' require 'chef/knife/deps_essentials' describe 'knife deps' do extend IntegrationSupport include KnifeSupport context 'local' do when_the_repository 'has a role with no run_list' do file 'roles/starring.json', {} it 'knife deps reports no dependencies' do knife('deps /roles/starring.json').should_succeed "/roles/starring.json\n" end end when_the_repository 'has a role with a default run_list' do file 'roles/starring.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } file 'roles/minor.json', {} file 'cookbooks/quiche/metadata.rb', 'name "quiche"' file 'cookbooks/quiche/recipes/default.rb', '' file 'cookbooks/soup/metadata.rb', 'name "soup"' file 'cookbooks/soup/recipes/chicken.rb', '' it 'knife deps reports all dependencies' do knife('deps /roles/starring.json').should_succeed < { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } } file 'roles/minor.json', {} file 'cookbooks/quiche/metadata.rb', 'name "quiche"' file 'cookbooks/quiche/recipes/default.rb', '' file 'cookbooks/soup/metadata.rb', 'name "soup"' file 'cookbooks/soup/recipes/chicken.rb', '' it 'knife deps reports all dependencies' do knife('deps /roles/starring.json').should_succeed < 'desert' } it 'knife deps reports just the node' do knife('deps /nodes/mort.json').should_succeed "/environments/desert.json\n/nodes/mort.json\n" end end when_the_repository 'has a node with roles and recipes in its run_list' do file 'roles/minor.json', {} file 'cookbooks/quiche/metadata.rb', 'name "quiche"' file 'cookbooks/quiche/recipes/default.rb', '' file 'cookbooks/soup/metadata.rb', 'name "soup"' file 'cookbooks/soup/recipes/chicken.rb', '' file 'nodes/mort.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } it 'knife deps reports just the node' do knife('deps /nodes/mort.json').should_succeed < %w(role[minor] recipe[quiche] recipe[soup::chicken]) } file 'roles/minor.json', {} file 'cookbooks/quiche/metadata.rb', 'name "quiche"' file 'cookbooks/quiche/recipes/default.rb', '' file 'cookbooks/soup/metadata.rb', 'name "soup"' file 'cookbooks/soup/recipes/chicken.rb', '' file 'environments/desert.json', {} file 'nodes/mort.json', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] } file 'nodes/bart.json', { 'run_list' => [ 'role[minor]' ] } it 'knife deps reports all dependencies' do knife('deps /nodes/mort.json').should_succeed < [ 'role[bar]' ] } file 'roles/bar.json', { 'run_list' => [ 'role[baz]' ] } file 'roles/baz.json', { 'run_list' => [ 'role[foo]' ] } file 'roles/self.json', { 'run_list' => [ 'role[self]' ] } it 'knife deps prints each once' do knife('deps /roles/foo.json /roles/self.json').should_succeed < 2, :stdout => "/blah\n", :stderr => "ERROR: /blah: No such file or directory\n" ) end it 'knife deps /roles/x.json reports an error' do knife('deps /roles/x.json').should_fail( :exit_code => 2, :stdout => "/roles/x.json\n", :stderr => "ERROR: /roles/x.json: No such file or directory\n" ) end it 'knife deps /nodes/x.json reports an error' do knife('deps /nodes/x.json').should_fail( :exit_code => 2, :stdout => "/nodes/x.json\n", :stderr => "ERROR: /nodes/x.json: No such file or directory\n" ) end it 'knife deps /environments/x.json reports an error' do knife('deps /environments/x.json').should_fail( :exit_code => 2, :stdout => "/environments/x.json\n", :stderr => "ERROR: /environments/x.json: No such file or directory\n" ) end it 'knife deps /cookbooks/x reports an error' do knife('deps /cookbooks/x').should_fail( :exit_code => 2, :stdout => "/cookbooks/x\n", :stderr => "ERROR: /cookbooks/x: No such file or directory\n" ) end it 'knife deps /data_bags/bag/item reports an error' do knife('deps /data_bags/bag/item').should_fail( :exit_code => 2, :stdout => "/data_bags/bag/item\n", :stderr => "ERROR: /data_bags/bag/item: No such file or directory\n" ) end end when_the_repository 'is missing a dependent cookbook' do file 'roles/starring.json', { 'run_list' => [ 'recipe[quiche]'] } it 'knife deps reports the cookbook, along with an error' do knife('deps /roles/starring.json').should_fail( :exit_code => 2, :stdout => "/cookbooks/quiche\n/roles/starring.json\n", :stderr => "ERROR: /cookbooks/quiche: No such file or directory\n" ) end end when_the_repository 'is missing a dependent environment' do file 'nodes/mort.json', { 'chef_environment' => 'desert' } it 'knife deps reports the environment, along with an error' do knife('deps /nodes/mort.json').should_fail( :exit_code => 2, :stdout => "/environments/desert.json\n/nodes/mort.json\n", :stderr => "ERROR: /environments/desert.json: No such file or directory\n" ) end end when_the_repository 'is missing a dependent role' do file 'roles/starring.json', { 'run_list' => [ 'role[minor]'] } it 'knife deps reports the role, along with an error' do knife('deps /roles/starring.json').should_fail( :exit_code => 2, :stdout => "/roles/minor.json\n/roles/starring.json\n", :stderr => "ERROR: /roles/minor.json: No such file or directory\n" ) end end end context 'invalid objects' do when_the_repository 'is empty' do it 'knife deps / reports itself only' do knife('deps /').should_succeed("/\n") end it 'knife deps /roles reports an error' do knife('deps /roles').should_fail( :exit_code => 2, :stderr => "ERROR: /roles: No such file or directory\n", :stdout => "/roles\n" ) end end when_the_repository 'has a data bag' do file 'data_bags/bag/item.json', '' it 'knife deps /data_bags/bag shows no dependencies' do knife('deps /data_bags/bag').should_succeed("/data_bags/bag\n") end end when_the_repository 'has a cookbook' do file 'cookbooks/blah/metadata.rb', 'name "blah"' it 'knife deps on a cookbook file shows no dependencies' do knife('deps /cookbooks/blah/metadata.rb').should_succeed( "/cookbooks/blah/metadata.rb\n" ) end end end end context 'remote' do when_the_chef_server 'has a role with no run_list' do role 'starring', {} it 'knife deps reports no dependencies' do knife('deps --remote /roles/starring.json').should_succeed "/roles/starring.json\n" end end when_the_chef_server 'has a role with a default run_list' do role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } role 'minor', {} cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } it 'knife deps reports all dependencies' do knife('deps --remote /roles/starring.json').should_succeed < { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } } role 'minor', {} cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } it 'knife deps reports all dependencies' do knife('deps --remote /roles/starring.json').should_succeed < 'desert' } it 'knife deps reports just the node' do knife('deps --remote /nodes/mort.json').should_succeed "/environments/desert.json\n/nodes/mort.json\n" end end when_the_chef_server 'has a node with roles and recipes in its run_list' do role 'minor', {} cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } node 'mort', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } it 'knife deps reports just the node' do knife('deps --remote /nodes/mort.json').should_succeed < "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } it 'knife deps reports just the cookbook' do knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/quiche\n" end end when_the_chef_server 'has a cookbook with dependencies' do cookbook 'kettle', '1.0.0', { 'metadata.rb' => "name 'kettle'\nversion '1.0.0'\n" } cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\ndepends 'kettle'\n", 'recipes' => { 'default.rb' => '' } } it 'knife deps reports the cookbook and its dependencies' do knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n" end end when_the_chef_server 'has a data bag' do data_bag 'bag', { 'item' => {} } it 'knife deps reports just the data bag' do knife('deps --remote /data_bags/bag/item.json').should_succeed "/data_bags/bag/item.json\n" end end when_the_chef_server 'has an environment' do environment 'desert', {} it 'knife deps reports just the environment' do knife('deps --remote /environments/desert.json').should_succeed "/environments/desert.json\n" end end when_the_chef_server 'has a deep dependency tree' do role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } role 'minor', {} cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } environment 'desert', {} node 'mort', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] } node 'bart', { 'run_list' => [ 'role[minor]' ] } it 'knife deps reports all dependencies' do knife('deps --remote /nodes/mort.json').should_succeed < "name 'foo'\ndepends 'bar'\n" } cookbook 'bar', '1.0.0', { 'metadata.rb' => "name 'bar'\ndepends 'baz'\n" } cookbook 'baz', '1.0.0', { 'metadata.rb' => "name 'baz'\ndepends 'foo'\n" } cookbook 'self', '1.0.0', { 'metadata.rb' => "name 'self'\ndepends 'self'\n" } it 'knife deps prints each once' do knife('deps --remote /cookbooks/foo /cookbooks/self').should_succeed < [ 'role[bar]' ] } role 'bar', { 'run_list' => [ 'role[baz]' ] } role 'baz', { 'run_list' => [ 'role[foo]' ] } role 'self', { 'run_list' => [ 'role[self]' ] } it 'knife deps prints each once' do knife('deps --remote /roles/foo.json /roles/self.json').should_succeed < 2, :stdout => "/blah\n", :stderr => "ERROR: /blah: No such file or directory\n" ) end it 'knife deps /roles/x.json reports an error' do knife('deps --remote /roles/x.json').should_fail( :exit_code => 2, :stdout => "/roles/x.json\n", :stderr => "ERROR: /roles/x.json: No such file or directory\n" ) end it 'knife deps /nodes/x.json reports an error' do knife('deps --remote /nodes/x.json').should_fail( :exit_code => 2, :stdout => "/nodes/x.json\n", :stderr => "ERROR: /nodes/x.json: No such file or directory\n" ) end it 'knife deps /environments/x.json reports an error' do knife('deps --remote /environments/x.json').should_fail( :exit_code => 2, :stdout => "/environments/x.json\n", :stderr => "ERROR: /environments/x.json: No such file or directory\n" ) end it 'knife deps /cookbooks/x reports an error' do knife('deps --remote /cookbooks/x').should_fail( :exit_code => 2, :stdout => "/cookbooks/x\n", :stderr => "ERROR: /cookbooks/x: No such file or directory\n" ) end it 'knife deps /data_bags/bag/item reports an error' do knife('deps --remote /data_bags/bag/item').should_fail( :exit_code => 2, :stdout => "/data_bags/bag/item\n", :stderr => "ERROR: /data_bags/bag/item: No such file or directory\n" ) end end when_the_chef_server 'is missing a dependent cookbook' do role 'starring', { 'run_list' => [ 'recipe[quiche]'] } it 'knife deps reports the cookbook, along with an error' do knife('deps --remote /roles/starring.json').should_fail( :exit_code => 2, :stdout => "/cookbooks/quiche\n/roles/starring.json\n", :stderr => "ERROR: /cookbooks/quiche: No such file or directory\n" ) end end when_the_chef_server 'is missing a dependent environment' do node 'mort', { 'chef_environment' => 'desert' } it 'knife deps reports the environment, along with an error' do knife('deps --remote /nodes/mort.json').should_fail( :exit_code => 2, :stdout => "/environments/desert.json\n/nodes/mort.json\n", :stderr => "ERROR: /environments/desert.json: No such file or directory\n" ) end end when_the_chef_server 'is missing a dependent role' do role 'starring', { 'run_list' => [ 'role[minor]'] } it 'knife deps reports the role, along with an error' do knife('deps --remote /roles/starring.json').should_fail( :exit_code => 2, :stdout => "/roles/minor.json\n/roles/starring.json\n", :stderr => "ERROR: /roles/minor.json: No such file or directory\n" ) end end end context 'invalid objects' do when_the_chef_server 'is empty' do it 'knife deps / reports an error' do knife('deps --remote /').should_succeed("/\n") end it 'knife deps /roles reports an error' do knife('deps --remote /roles').should_succeed("/roles\n") end end when_the_chef_server 'has a data bag' do data_bag 'bag', { 'item' => {} } it 'knife deps /data_bags/bag shows no dependencies' do knife('deps --remote /data_bags/bag').should_succeed("/data_bags/bag\n") end end when_the_chef_server 'has a cookbook' do cookbook 'blah', '1.0.0', { 'metadata.rb' => 'name "blah"' } it 'knife deps on a cookbook file shows no dependencies' do knife('deps --remote /cookbooks/blah/metadata.rb').should_succeed( "/cookbooks/blah/metadata.rb\n" ) end end end end it 'knife deps --no-recurse reports an error' do knife('deps --no-recurse /').should_fail("ERROR: --no-recurse requires --tree\n") end end