Sha256: 7ad34d427f1698cd97247469fdbf8dc089ebe93caefb87a5ca0ff6550337caf5

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require 'test_plugin_helper'

class DockerRegistryTest < ActiveSupport::TestCase
  subject { FactoryBot.create(:docker_registry) }

  test 'used_location_ids should return correct location ids' do
    location = FactoryBot.build(:location)
    r = as_admin do
      FactoryBot.create(:docker_registry, :locations => ([location]))
    end
    assert r.used_location_ids.include?(location.id)
  end

  test 'used_organization_ids should return correct organization ids' do
    organization = FactoryBot.build(:organization)
    r = as_admin do
      FactoryBot.create(:docker_registry, :organizations => ([organization]))
    end
    assert r.used_organization_ids.include?(organization.id)
  end

  test 'password is stored encrypted' do
    registry = as_admin { FactoryBot.build(:docker_registry) }
    registry.password = 'encrypted-whatever'
    DockerRegistry.any_instance.expects(:encryption_key).at_least_once.returns('fakeencryptionkey')
    assert registry.is_decryptable?(registry.password_in_db)
  end

  should validate_presence_of(:name)
  should validate_presence_of(:url)
  should validate_uniqueness_of(:name)
  should validate_uniqueness_of(:url)

  describe 'registry validation' do
    setup do
      subject.unstub(:attempt_login)
    end

    test 'is valid when the api is ok' do
      subject.api.expects(:ok?).returns(true)
      assert subject.valid?
    end

    test 'is not valid when api is not ok' do
      subject.api.expects(:ok?)
        .raises(Docker::Error::AuthenticationError)
      refute subject.valid?
    end
  end

  describe '#api' do
    let(:api) { subject.api }

    test 'returns a RegistryApi instance' do
      assert_kind_of Service::RegistryApi, api
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_docker-5.0.0 test/units/docker_registry_test.rb
foreman_docker-4.1.1 test/units/docker_registry_test.rb
foreman_docker-4.1.0 test/units/docker_registry_test.rb
foreman_docker-4.0.0 test/units/docker_registry_test.rb