Skip to content

Commit

Permalink
Fix Docker::Image.create
Browse files Browse the repository at this point in the history
The credential-header-logic was a bit off, this commit fixes it and adds
a test.
  • Loading branch information
nahiluhmot committed Mar 19, 2014
1 parent 237f208 commit 8389e16
Show file tree
Hide file tree
Showing 4 changed files with 713 additions and 47 deletions.
11 changes: 4 additions & 7 deletions lib/docker/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ class << self

# Create a new Image.
def create(opts = {}, creds = nil, conn = Docker.connection)
credentials = (creds.nil?) ? creds.to_json : Docker.creds
headers = if credentials.nil?
Docker::Util.build_auth_header(credentials)
else
{}
end
body = conn.post('/images/create', opts)
credentials = creds.nil? ? Docker.creds : creds.to_json
headers = !credentials.nil? && Docker::Util.build_auth_header(credentials)
headers ||= {}
body = conn.post('/images/create', opts, :headers => headers)
id = Docker::Util.fix_json(body).last['id']
new(conn, 'id' => id, :headers => headers)
end
Expand Down
14 changes: 12 additions & 2 deletions spec/docker/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,24 @@
subject { described_class }

context 'when the Image does not yet exist and the body is a Hash' do
let(:image) { subject.create('fromImage' => 'base') }
let(:image) { subject.create('fromImage' => 'ubuntu') }
let(:creds) {
{
:username => 'nahiluhmot',
:password => '*********',
:email => '[email protected]'
}
}

before { Docker.creds = creds }

it 'sets the id', :vcr do
it 'sets the id and sends Docker.creds', :vcr do
image.should be_a Docker::Image
image.id.should match(/\A[a-fA-F0-9]+\Z/)
image.id.should_not include('base')
image.id.should_not be_nil
image.id.should_not be_empty
image.info[:headers].keys.should include('X-Registry-Auth')
end
end
end
Expand Down

This file was deleted.

Loading

0 comments on commit 8389e16

Please sign in to comment.