Sha256: 68c25703feb2d18080e66354d29287c91fc9b34196c80fd09d225cc88c56e4b1

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

describe Docker::Util do
  subject { described_class }

  describe '.parse_json' do
    subject { described_class.parse_json(arg) }

    context 'when the argument is nil' do
      let(:arg) { nil }

      it { should be_nil }
    end

    context 'when the argument is empty' do
      let(:arg) { '' }

      it { should be_nil }
    end

    context 'when the argument is \'null\'' do
      let(:arg) { 'null' }

      it { should be_nil }
    end

    context 'when the argument is not valid JSON' do
      let(:arg) { '~~lol not valid json~~' }

      it 'raises an error' do
        expect { subject }.to raise_error Docker::Error::UnexpectedResponseError
      end
    end

    context 'when the argument is valid JSON' do
      let(:arg) { '{"yolo":"swag"}' }

      it 'parses the JSON into a Hash' do
        subject.should == { 'yolo' => 'swag' }
      end
    end
  end

  describe '.build_auth_header' do
    subject { described_class }

    let(:credentials) {
      {
        :username      => 'test',
        :password      => 'password',
        :email         => 'test@example.com',
        :serveraddress => 'https://registry.com/'
      }
    }
    let(:credential_string) { credentials.to_json }
    let(:x_registry_auth) { Base64.encode64(credential_string).gsub(/\n/, '') }
    let(:expected_headers) { { 'X-Registry-Auth' => x_registry_auth } }


    context 'given credentials as a Hash' do
      it 'returns an X-Registry-Auth header encoded' do
        expect(subject.build_auth_header(credentials)).to eq(expected_headers)
      end
    end

    context 'given credentials as a String' do
      it 'returns an X-Registry-Auth header encoded' do
        expect(
          subject.build_auth_header(credential_string)
        ).to eq(expected_headers)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
docker-api-1.8.4 spec/docker/util_spec.rb
docker-api-1.8.3 spec/docker/util_spec.rb
docker-api-1.8.2 spec/docker/util_spec.rb
docker-api-1.8.1 spec/docker/util_spec.rb
docker-api-1.8.0 spec/docker/util_spec.rb
docker-api-1.7.6 spec/docker/util_spec.rb
docker-api-1.7.5 spec/docker/util_spec.rb
docker-api-1.7.4 spec/docker/util_spec.rb
docker-api-1.7.3 spec/docker/util_spec.rb
docker-api-1.7.2 spec/docker/util_spec.rb