blob: 70b77d8bf4bf555af2c7128f8ebf667c20732ea2 [file] [log] [blame]
Matt Chua05d2152014-04-19 23:40:56 -07001require 'chefspec'
2require 'chefspec/berkshelf'
Matt Chua05d2152014-04-19 23:40:56 -07003require 'spec_helper.rb'
Matt Chua05d2152014-04-19 23:40:56 -07004
Matt Chu99bc59a2014-08-21 14:44:15 -07005shared_examples 'general tests' do |platform, platform_version|
6 context "on #{platform} #{platform_version}" do
Matt Chua05d2152014-04-19 23:40:56 -07007
Matt Chua05d2152014-04-19 23:40:56 -07008 let(:chef_run) do
Matt Chu9653bf82015-04-27 17:09:17 -07009 ChefSpec::SoloRunner.new(
Matt Chuf4ba1a42014-08-21 14:12:42 -070010 platform: platform,
Matt Chu99bc59a2014-08-21 14:44:15 -070011 # TODO get this working; that is, figure out how to stub this properly
12 #version: platform_version,
13 #step_into: [ 'anaconda_package' ]) do |node|
Matt Chu9653bf82015-04-27 17:09:17 -070014 version: platform_version
15 ) do |node|
16 # explicitly set the flavor for tests
17 # TODO test autodetection of x86 versus x86_64
18 node.set['anaconda']['flavor'] = 'x86_64'
Matt Chua05d2152014-04-19 23:40:56 -070019 end
20 end
Matt Chua05d2152014-04-19 23:40:56 -070021
Matt Chu126302c2014-08-21 14:26:55 -070022 before do
Matt Chu99bc59a2014-08-21 14:44:15 -070023 # TODO doesn't work
24 #stub_command('/opt/anaconda/2.0.1/bin/conda install astroid --yes').and_return(true)
25 #stub_command('/opt/anaconda/2.0.1/bin/conda remove astroid --yes').and_return(true)
Matt Chu4c42be02014-08-20 16:56:42 -070026
27 stub_command("rpm -qa | grep -q '^runit'").and_return(true)
Matt Chu126302c2014-08-21 14:26:55 -070028 end
29
Matt Chubdc11ef2014-08-11 12:51:45 -070030 it 'runs without errors. see test-kitchen tests for more comprehensive tests that are not possible here' do
Matt Chua05d2152014-04-19 23:40:56 -070031 chef_run.converge(described_recipe)
32
Matt Chubdc11ef2014-08-11 12:51:45 -070033 expect(chef_run).to create_directory('/opt/anaconda')
Matt Chu9a27cc72014-04-20 14:36:21 -070034 expect(chef_run).to run_bash('run anaconda installer')
Matt Chua05d2152014-04-19 23:40:56 -070035 end
36
Matt Chu1b82b9c2014-04-20 10:51:53 -070037 it 'generates the installer template correctly' do
38 chef_run.converge(described_recipe)
39
40 # must be exactly 4 lines
Matt Chu30eb44e2014-04-20 12:02:00 -070041 installer_config_path = "#{Chef::Config[:file_cache_path]}/installer_config"
42 expect(chef_run).to render_file(installer_config_path).with_content(/.*\n.*\n.*\n.*/)
Matt Chu1b82b9c2014-04-20 10:51:53 -070043 end
Matt Chua05d2152014-04-19 23:40:56 -070044
Matt Chu4c42be02014-08-20 16:56:42 -070045 it 'has the anaconda_package resource' do
Matt Chu412e8562014-06-28 13:57:45 -070046 chef_run.converge('recipe[anaconda::package_tests]')
47
Matt Chu99bc59a2014-08-21 14:44:15 -070048 package_name = 'astroid'
49
Matt Chu4c42be02014-08-20 16:56:42 -070050 expect(chef_run).to install_anaconda_package(package_name)
Matt Chu99bc59a2014-08-21 14:44:15 -070051 # TODO we want this test, but needs to be stubbed
52 #expect(chef_run).to run_execute("conda_package_install_#{package_name}").with(
53 #command: '/opt/anaconda/2.0.1/bin/conda install astroid --yes'
54 #)
55
Matt Chu4c42be02014-08-20 16:56:42 -070056 expect(chef_run).to remove_anaconda_package(package_name)
Matt Chu99bc59a2014-08-21 14:44:15 -070057 # TODO we want this test, but needs to be stubbed
58 #expect(chef_run).to run_execute("conda_package_remove_#{package_name}").with(
59 #command: '/opt/anaconda/2.0.1/bin/conda remove astroid --yes'
60 #)
Matt Chubdc11ef2014-08-11 12:51:45 -070061
62 # for coverage
63 expect(chef_run).to write_log('do NOT include this in your runlist! for testing only.')
Matt Chu412e8562014-06-28 13:57:45 -070064 end
65
Matt Chu4c42be02014-08-20 16:56:42 -070066 it 'has the anaconda_nbservice resource' do
67 chef_run.converge('recipe[anaconda::notebook_server]')
68
69 expect(chef_run).to create_anaconda_nbservice('notebook-server')
70 end
71
Matt Chu412e8562014-06-28 13:57:45 -070072 it 'provides a convenience shell script' do
Matt Chubdc11ef2014-08-11 12:51:45 -070073 chef_run.converge('recipe[anaconda::shell_conveniences]')
Matt Chu412e8562014-06-28 13:57:45 -070074
Matt Chubdc11ef2014-08-11 12:51:45 -070075 expect(chef_run).to create_template('/etc/profile.d/anaconda-env.sh')
76 end
77
78 it 'caches the installer template' do
79 chef_run.converge(described_recipe)
80
81 installer = "Anaconda-#{chef_run.node.anaconda.version}-Linux-#{chef_run.node.anaconda.flavor}.sh"
82 installer_path = "#{Chef::Config[:file_cache_path]}/#{installer}"
83
84 expect(chef_run).to create_remote_file_if_missing(installer_path)
Matt Chu412e8562014-06-28 13:57:45 -070085 end
86
Matt Chub2e24b72014-09-07 14:35:37 -070087 it 'has a workaround for python: https://github.com/thmttch/chef-continuum-anaconda/issues/12' do
Matt Chu9653bf82015-04-27 17:09:17 -070088 skip('How do you include a cookbook for testing purposes only? Needs python')
Matt Chub2e24b72014-09-07 14:35:37 -070089
90 chef_run.converge('python::default')
91 chef_run.converge(described_recipe)
Matt Chu0530ec22014-10-12 11:07:14 -070092 chef_run.converge('anaconda::python_workaround')
Matt Chub2e24b72014-09-07 14:35:37 -070093
94 # TODO test that python_pip[setuptools] is removed/disabled
95 end
96
Matt Chua05d2152014-04-19 23:40:56 -070097 end
98end
99
Matt Chu3d313522014-04-20 20:53:28 -0700100describe 'anaconda::default' do
Matt Chu9653bf82015-04-27 17:09:17 -0700101 # https://github.com/customink/fauxhai/tree/master/lib/fauxhai/platforms
Matt Chua05d2152014-04-19 23:40:56 -0700102 platforms = {
Matt Chu9653bf82015-04-27 17:09:17 -0700103 'ubuntu' => [ '12.04', '14.04', '15.04' ],
104 # TODO 7.9 and 8.2 were recently released
105 'debian' => [ '7.8', '8.1' ],
106 # TODO 6.7 is the latest
107 'centos' => [ '5.11', '6.6', '7.1.1503' ],
108 'redhat' => [ '5.9', '6.6', '7.1' ],
Matt Chua05d2152014-04-19 23:40:56 -0700109 }
110
111 platforms.each do |platform, versions|
Matt Chubdc11ef2014-08-11 12:51:45 -0700112 versions.each do |platform_version|
113 Fauxhai.mock(platform: platform, version: platform_version)
114 include_examples 'general tests', platform, platform_version
Matt Chua05d2152014-04-19 23:40:56 -0700115 end
116 end
117end