forked from sous-chefs/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker_registry resource should have 'host' property
Signed-off-by: S.Cavallo <[email protected]>
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../libraries/docker_base' | ||
require_relative '../../libraries/docker_registry' | ||
|
||
describe 'docker_registry' do | ||
step_into :docker_registry | ||
platform 'ubuntu' | ||
|
||
# Info returned by docker api | ||
# https://docs.docker.com/engine/api/v1.39/#section/Authentication | ||
let(:auth) do | ||
{ | ||
'identitytoken' => '9cbafc023786cd7...' | ||
}.to_json | ||
end | ||
|
||
before do | ||
# Ensure docker api calls are mocked | ||
# It is low level much easier to do in Excon | ||
# Plus, the low level mock allows testing this cookbook | ||
# for multiple docker apis and docker-api gems | ||
# https://github.com/excon/excon#stubs | ||
Excon.defaults[:mock] = true | ||
Excon.stub({ method: :post, path: '/v1.16/auth' }, body: auth, status: 200) | ||
end | ||
|
||
context 'logs into a docker registry with default options' do | ||
recipe do | ||
docker_registry 'chefspec_custom_registry' do | ||
email 'chefspec_email' | ||
password 'chefspec_password' | ||
username 'chefspec_username' | ||
end | ||
end | ||
it { | ||
expect { chef_run }.to_not raise_error | ||
expect(chef_run).to login_docker_registry('chefspec_custom_registry').with( | ||
email: 'chefspec_email', | ||
password: 'chefspec_password', | ||
username: 'chefspec_username', | ||
host: nil | ||
) | ||
} | ||
end | ||
|
||
context 'logs into a docker registry with host' do | ||
recipe do | ||
docker_registry 'chefspec_custom_registry' do | ||
email 'chefspec_email' | ||
password 'chefspec_password' | ||
username 'chefspec_username' | ||
host 'chefspec_host' | ||
end | ||
end | ||
it { | ||
expect { chef_run }.to_not raise_error | ||
expect(chef_run).to login_docker_registry('chefspec_custom_registry').with( | ||
email: 'chefspec_email', | ||
password: 'chefspec_password', | ||
username: 'chefspec_username', | ||
host: 'chefspec_host' | ||
) | ||
} | ||
end | ||
|
||
context 'logs into a docker registry with host environment variable' do | ||
recipe do | ||
docker_registry 'chefspec_custom_registry' do | ||
email 'chefspec_email' | ||
password 'chefspec_password' | ||
username 'chefspec_username' | ||
end | ||
end | ||
it { | ||
# Set the environment variable | ||
stub_const 'ENV', ENV.to_h.merge('DOCKER_HOST' => 'chefspec_host_environment_variable') | ||
|
||
expect { chef_run }.to_not raise_error | ||
expect(chef_run).to login_docker_registry('chefspec_custom_registry').with( | ||
email: 'chefspec_email', | ||
password: 'chefspec_password', | ||
username: 'chefspec_username', | ||
host: 'chefspec_host_environment_variable' | ||
) | ||
} | ||
end | ||
end |