Project

General

Profile

Revision 466cd5ba

Added by Daniel Lobato Garcia over 8 years ago

Fixes #7912 - Wizard path error and tests

View differences:

README.md
18 18
| ---------------:| --------------:|
19 19
| >=  1.5         | 0.0.1          |
20 20

  
21
## Testing
22

  
23
Run `rake test:docker:test` from your Foreman directory to run the test suite.
24

  
21 25
## Latest code
22 26

  
23 27
You can get the develop branch of the plugin by specifying your Gemfile in this way:
app/controllers/containers_controller.rb
1 1
class ContainersController < ::ApplicationController
2 2
  def index
3 3
    @container_resources = allowed_resources.select { |cr| cr.provider == 'Docker' }
4
    if @container_resources.empty?
5
      warning('You need a Compute Resource of type Docker to start managing containers')
6
      redirect_to new_compute_resource_path
7
    end
4 8
  # This should only rescue Fog::Errors, but Fog returns all kinds of errors...
5 9
  rescue
6 10
    process_error
......
8 12

  
9 13
  def new
10 14
    @container = Container.create
11
    redirect_to container_steps_path(:container_id => @container.id)
15
    redirect_to container_step_path(:container_id => @container.id, :id => :preliminary)
12 16
  end
13 17

  
14 18
  private
lib/foreman_docker/engine.rb
39 39
      end
40 40

  
41 41
    end
42

  
43
    rake_tasks do
44
      load "#{ForemanDocker::Engine.root}/lib/foreman_docker/tasks/test.rake"
45
    end
42 46
  end
43 47

  
48

  
44 49
  # extend fog docker server and image models.
45 50
  require 'fog/fogdocker/models/compute/server'
46 51
  require 'fog/fogdocker/models/compute/image'
lib/foreman_docker/tasks/test.rake
1
require File.expand_path("../engine", File.dirname(__FILE__))
2
namespace :test do
3
   namespace :docker do
4

  
5
    desc "Run the plugin unit test suite."
6
    task :test => ['db:test:prepare'] do
7
      test_task = Rake::TestTask.new('docker_test_task') do |t|
8
        t.libs << ["test", "#{ForemanDocker::Engine.root}/test"]
9
        t.test_files = [
10
          "#{ForemanDocker::Engine.root}/test/**/*_test.rb",
11
        ]
12
        t.verbose = true
13
      end
14

  
15
      Rake::Task[test_task.name].invoke
16
    end
17
  end
18
end
19

  
20
Rake::Task[:test].enhance do
21
  Rake::Task['test:docker'].invoke
22
end
test/factories/compute_resources.rb
1
FactoryGirl.define do
2
  factory :container_resource, :class => ComputeResource do
3
    sequence(:name) { |n| "compute_resource#{n}" }
4

  
5
    trait :docker do
6
      provider 'Docker'
7
      user 'dockeruser'
8
      password 'dockerpassword'
9
      email 'container@containerization.com'
10
      url 'unix:///var/run/docker.sock'
11
    end
12

  
13
    factory :docker_cr, :class => ForemanDocker::Docker, :traits => [:docker]
14
  end
15
end
test/foreman_docker_test.rb
1
require 'test_helper'
2

  
3
class ForemanDockerTest < ActiveSupport::TestCase
4
  test 'truth' do
5
    assert_kind_of Module, ForemanDocker
6
  end
7
end
test/functionals/containers_controller_test.rb
1
require 'test_plugin_helper'
2

  
3
class ContainersControllerTest < ActionController::TestCase
4
  test 'redirect if Docker provider is not available' do
5
    get :index, {}, set_session_user
6
    assert_redirected_to new_compute_resource_path
7
  end
8

  
9
  test 'index if Docker resource is available' do
10
    Fog.mock!
11
    # Avoid rendering errors by not retrieving any container
12
    ComputeResource.any_instance.stubs(:vms).returns([])
13
    FactoryGirl.create(:docker_cr)
14
    get :index, {}, set_session_user
15
    assert_template 'index'
16
  end
17
end
test/test_helper.rb
1
# Configure Rails Environment
2
ENV['RAILS_ENV'] = 'test'
3

  
4
require File.expand_path('../dummy/config/environment.rb',  __FILE__)
5
require 'rails/test_help'
6

  
7
Rails.backtrace_cleaner.remove_silencers!
8

  
9
# Load support files
10
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11

  
12
# Load fixtures from the engine
13
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
  ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
15
end
test/test_plugin_helper.rb
1
# This calls the main test_helper in Foreman-core
2
require 'test_helper'
3

  
4
def assert_row_button(index_path, link_text, button_text, dropdown = false)
5
  visit index_path
6
  within(:xpath, "//tr[contains(.,'#{link_text}')]") do
7
    find("i.caret").click if dropdown
8
    click_link(button_text)
9
  end
10
end
11

  
12
# Add plugin to FactoryGirl's paths
13
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
14
FactoryGirl.reload

Also available in: Unified diff