Skip to content

Commit

Permalink
- Updating to Berkshelf 4
Browse files Browse the repository at this point in the history
- Adding a spec for a resource in docker_test::image. Found a world of strange behavior.
  • Loading branch information
Sean OMeara committed Oct 7, 2015
1 parent 49de31b commit 09de6ae
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group :lint do
end

group :unit do
gem 'berkshelf', '~> 3.2'
gem 'berkshelf', '~> 4.0'
gem 'chefspec', github: 'jkeiser/chefspec', branch: 'jk/chefspec-12.5'
end

Expand Down
104 changes: 79 additions & 25 deletions spec/docker_test/image_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,87 @@
require 'spec_helper'

describe 'docker_test::image' do
cached(:chef_run) do
ChefSpec::SoloRunner.new
.converge('docker_test::image')
end

# before do
# stub_command('/usr/bin/test -f /tmp/registry/tls/ca-key.pem').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/server-key.pem').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/server.csr').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/server.pem').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/key.pem').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/client.csr').and_return(true)
# stub_command('/usr/bin/test -f /tmp/registry/tls/cert.pem').and_return(true)
# stub_command("[ ! -z `docker ps -qaf 'name=registry_service$'` ]").and_return(true)
# stub_command("[ ! -z `docker ps -qaf 'name=registry_proxy$'` ]").and_return(true)

# allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original
# allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('docker_test::default')
# end
cached(:chef_run) { ChefSpec::SoloRunner.converge('docker_test::image') }

# it 'includes recipe docker_test::default' do
# expect_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('docker_test::default')
# end
before do
stub_command('/usr/bin/test -f /tmp/registry/tls/ca-key.pem').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/server-key.pem').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/server.csr').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/server.pem').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/key.pem').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/client.csr').and_return(true)
stub_command('/usr/bin/test -f /tmp/registry/tls/cert.pem').and_return(true)
stub_command("[ ! -z `docker ps -qaf 'name=registry_service$'` ]").and_return(true)
stub_command("[ ! -z `docker ps -qaf 'name=registry_proxy$'` ]").and_return(true)
end

# I found some weird behavior with Chef 12.4.3.
context 'when compiling the recipe' do
# it 'pulls docker_image[hello-world]' do
# expect(chef_run).to pull_docker_image('hello-world')
# end
it 'pulls docker_image[hello-world]' do
expect(chef_run).to pull_docker_image('hello-world').with(
container_name: nil, # expected 'hello-world'
repo: 'hello-world',
tag: 'latest',
command: nil, # expected ''
api_retries: 3,
attach_stderr: nil, # expected true
attach_stdin: nil, # expected false
attach_stdout: nil, # expected true
autoremove: nil, # expected false
binds: nil,
cap_add: nil,
cap_drop: nil,
cgroup_parent: nil, # expecting ''
cpu_shares: nil, # expecting 0
cpuset_cpus: nil, # expecting ''
detach: nil, # expecting true
devices: nil,
dns: nil,
dns_search: nil,
domain_name: nil, # expecting ''
entrypoint: nil,
env: nil,
extra_hosts: nil,
exposed_ports: nil,
force: false,
host: nil,
host_name: nil,
labels: nil,
links: nil,
log_config: nil,
log_driver: nil,
log_opts: nil, # expecting []
mac_address: nil, # expecting ''
memory: nil, # expecting 0
memory_swap: nil, # expecting -1
network_disabled: nil, # expecting false
network_mode: nil,
open_stdin: nil, # expecting false
outfile: nil,
port: nil,
port_bindings: nil,
privileged: nil, # expecting false
publish_all_ports: nil, # expecting false
read_timeout: 120, # expecting 60
remove_volumes: nil, # expecting false
restart_maximum_retry_count: nil, # expecting 0
restart_policy: nil, # expecting 'no'
security_opts: nil, # expecting ['']
signal: nil, # expecting 'SIGKILL'
stdin_once: nil, # expecting false
# timeout: nil, # causes a chefspec error
tty: nil, # expecting false
ulimits: nil,
user: nil, # expecting ''
volumes: nil,
volumes_from: nil,
working_dir: nil,
write_timeout: nil
)
end

it 'includes the "docker_test::registry" recipe' do
expect(chef_run).to include_recipe('docker_test::registry')
end
end
end

0 comments on commit 09de6ae

Please sign in to comment.