-
Notifications
You must be signed in to change notification settings - Fork 13
/
default_spec.rb
117 lines (91 loc) · 4.05 KB
/
default_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'chefspec'
require 'chefspec/berkshelf'
require 'spec_helper.rb'
shared_examples 'general tests' do |platform, platform_version|
context "on #{platform} #{platform_version}" do
let(:chef_run) do
ChefSpec::SoloRunner.new(
platform: platform,
# TODO get this working; that is, figure out how to stub this properly
#version: platform_version,
#step_into: [ 'anaconda_package' ]) do |node|
version: platform_version
) do |node|
# explicitly set the flavor for tests
# TODO test autodetection of x86 versus x86_64
node.set['anaconda']['flavor'] = 'x86_64'
end
end
before do
# TODO doesn't work
#stub_command('/opt/anaconda/2.0.1/bin/conda install astroid --yes').and_return(true)
#stub_command('/opt/anaconda/2.0.1/bin/conda remove astroid --yes').and_return(true)
stub_command("rpm -qa | grep -q '^runit'").and_return(true)
end
it 'runs without errors. see test-kitchen tests for more comprehensive tests that are not possible here' do
chef_run.converge(described_recipe)
expect(chef_run).to create_directory('/opt/anaconda')
expect(chef_run).to run_bash('run anaconda installer')
end
it 'generates the installer template correctly' do
chef_run.converge(described_recipe)
# must be exactly 4 lines
installer_config_path = "#{Chef::Config[:file_cache_path]}/installer_config"
expect(chef_run).to render_file(installer_config_path).with_content(/.*\n.*\n.*\n.*/)
end
it 'has the anaconda_package resource' do
chef_run.converge('recipe[anaconda::package_tests]')
package_name = 'astroid'
expect(chef_run).to install_anaconda_package(package_name)
# TODO we want this test, but needs to be stubbed
#expect(chef_run).to run_execute("conda_package_install_#{package_name}").with(
#command: '/opt/anaconda/2.0.1/bin/conda install astroid --yes'
#)
expect(chef_run).to remove_anaconda_package(package_name)
# TODO we want this test, but needs to be stubbed
#expect(chef_run).to run_execute("conda_package_remove_#{package_name}").with(
#command: '/opt/anaconda/2.0.1/bin/conda remove astroid --yes'
#)
# for coverage
expect(chef_run).to write_log('do NOT include this in your runlist! for testing only.')
end
it 'has the anaconda_nbservice resource' do
chef_run.converge('recipe[anaconda::notebook_server]')
expect(chef_run).to create_anaconda_nbservice('notebook-server')
end
it 'provides a convenience shell script' do
chef_run.converge('recipe[anaconda::shell_conveniences]')
expect(chef_run).to create_template('/etc/profile.d/anaconda-env.sh')
end
it 'caches the installer template' do
chef_run.converge(described_recipe)
installer = "Anaconda-#{chef_run.node.anaconda.version}-Linux-#{chef_run.node.anaconda.flavor}.sh"
installer_path = "#{Chef::Config[:file_cache_path]}/#{installer}"
expect(chef_run).to create_remote_file_if_missing(installer_path)
end
it 'has a workaround for python: https://github.com/thmttch/chef-continuum-anaconda/issues/12' do
skip('How do you include a cookbook for testing purposes only? Needs python')
chef_run.converge('python::default')
chef_run.converge(described_recipe)
chef_run.converge('anaconda::python_workaround')
# TODO test that python_pip[setuptools] is removed/disabled
end
end
end
describe 'anaconda::default' do
# https://github.com/customink/fauxhai/tree/master/lib/fauxhai/platforms
platforms = {
'ubuntu' => [ '12.04', '14.04', '15.04' ],
# TODO 7.9 and 8.2 were recently released
'debian' => [ '7.8', '8.1' ],
# TODO 6.7 is the latest
'centos' => [ '5.11', '6.6', '7.1.1503' ],
'redhat' => [ '5.9', '6.6', '7.1' ],
}
platforms.each do |platform, versions|
versions.each do |platform_version|
Fauxhai.mock(platform: platform, version: platform_version)
include_examples 'general tests', platform, platform_version
end
end
end