Project

General

Profile

Revision dce03a1e

Added by Ondřej Pražák about 7 years ago

cleaning up tests

View differences:

Rakefile
1 1
#!/usr/bin/env rake
2
begin
3
  require 'bundler/setup'
4
rescue LoadError
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
end
7
begin
8
  require 'rdoc/task'
9
rescue LoadError
10
  require 'rdoc/rdoc'
11
  require 'rake/rdoctask'
12
  RDoc::Task = Rake::RDocTask
13
end
14

  
15
RDoc::Task.new(:rdoc) do |rdoc|
16
  rdoc.rdoc_dir = 'rdoc'
17
  rdoc.title    = 'ForemanPipeline'
18
  rdoc.options << '--line-numbers'
19
  rdoc.rdoc_files.include('README.rdoc')
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
end
22

  
23
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
load 'rails/tasks/engine.rake'
25

  
26

  
27

  
28
Bundler::GemHelper.install_tasks
29

  
30
require 'rake/testtask'
31

  
32
Rake::TestTask.new(:test) do |t|
33
  t.libs << 'lib'
34
  t.libs << 'test'
35
  t.pattern = 'test/**/*_test.rb'
36
  t.verbose = true
37
end
38

  
39

  
40
task :default => :test
2
# useful tasks to be found in lib/foreman_pipeline/tasks
lib/foreman_pipeline/tasks/foreman_pipeline_seed.rake
12 12
        tmplt.update_attributes(defaults.merge(template))
13 13
      end
14 14
    end
15
    
16 15
  end
17
  
18 16
end
lib/foreman_pipeline/tasks/foreman_pipeline_test.rake
1 1
require File.expand_path("../engine", File.dirname(__FILE__))
2 2

  
3 3
namespace :test do
4
  
5
  namespace :foreman_pipeline do
6
    
7
    task :test => ['db:test:prepare'] do
8
      test_task = Rake::TestTask.new('foreman_pipeline_test_task') do |t|
9
        t.libs << ["test", "#{ForemanPipeline::Engine.root}/test"]
10
        t.test_files = ["#{ForemanPipeline::Engine.root}/test/**/*_test.rb"]
11
        t.verbose = true
12
      end
13
      Rake::Task[test_task.name].invoke
14
    end
15 4

  
16
    task :spec => ['db:test:prepare'] do
17
      test_task = Rake::TestTask.new('foreman_pipeline_spec_task') do |t|
18
        t.libs << ["spec", "#{ForemanPipeline::Engine.root}/spec", "test", "#{ForemanPipeline::Engine.root}/test"]
19
        t.test_files = ["#{ForemanPipeline::Engine.root}/spec/**/*_spec.rb"]
20
        t.verbose = true
21
      end
22
      Rake::Task[test_task.name].invoke
5
  task :foreman_pipeline => ['db:test:prepare'] do
6
    test_task = Rake::TestTask.new('foreman_pipeline_test_task') do |t|
7
      t.libs << ["test", "#{ForemanPipeline::Engine.root}/test"]
8
      t.test_files = ["#{ForemanPipeline::Engine.root}/test/**/*_test.rb"]
9
      t.verbose = true
23 10
    end
11
    Rake::Task[test_task.name].invoke
24 12
  end
13
end
25 14

  
15
Rake::Task[:test].enhance do
16
  Rake::Task['test:foreman_pipeline'].invoke
17
end
26 18

  
27
  desc "run all plugin's tests"
28
  task :foreman_pipeline do
29
    Rake::Task['test:foreman_pipeline:test'].invoke
30
    Rake::Task['test:foreman_pipeline:spec'].invoke
19
load 'tasks/jenkins.rake'
20
if Rake::Task.task_defined?(:'jenkins:unit')
21
  Rake::Task["jenkins:unit"].enhance do
22
    Rake::Task['test:foreman_pipeline'].invoke
31 23
  end
32

  
33
end
34
  
24
end
spec/models/jenkins_instance_spec.rb
1
require 'foreman_pipeline_plugin_test_helper'
2

  
3
module ForemanPipeline
4
  describe JenkinsInstance do
5
    include Katello::OrchestrationHelper
6

  
7
    let(:i_name) {"test_jenkins_instance"}
8
    let(:certpath) {"/home/user/.ssh/foreman-jenkins"}
9
    let(:home) {"/var/lib/jenkins"}
10
    let(:valid_url) {"http://somewhere.com:8080"}
11

  
12
    before(:each) do
13
      disable_org_orchestration
14

  
15
      @org = get_organization
16
      @instance = JenkinsInstance.create(:name => i_name,
17
                                          :url => valid_url,
18
                                          :cert_path => certpath,
19
                                          :jenkins_home => home,
20
                                          :organization_id => @org.id)
21
    end
22

  
23
    describe "in valid state" do
24
      it "should be valid" do
25
        @instance.must_be :valid?
26
        @instance.errors[:base].must_be_empty
27
      end
28
    end
29

  
30
    describe "in invalid state" do
31
      before {@instance = JenkinsInstance.new}
32

  
33
      it "sould be invalid when empty" do
34
        @instance.wont_be :valid?
35
        @instance.errors[:organization].wont_be_empty
36
        @instance.errors[:name].wont_be_empty
37
        @instance.errors[:url].wont_be_empty
38
        @instance.errors[:cert_path].wont_be_empty
39
        @instance.errors[:jenkins_home].wont_be_empty
40
      end
41
    end
42

  
43
    describe "creating" do
44
      it "should be able to create" do
45
        @instance.wont_be :nil?
46
      end
47

  
48
      it "should not create with invalid url"  do
49
        # inst = JenkinsInstance.create(:name => i_name,
50
        #                               :url => "url_input_fail",
51
        #                               :cert_path => )
52
      end
53
    end
54

  
55

  
56

  
57
    describe "updating" do
58

  
59
      it "should accept name" do
60
        j = JenkinsInstance.find_by_name(i_name)
61
        j.wont_be :nil?
62
        new_name = j.name << "_name_changed"
63
        k = JenkinsInstance.update(j.id, :name => new_name)
64
        k.name.must_equal new_name
65
      end
66

  
67
      it "should accept jenkins_home" do
68
        j = JenkinsInstance.find_by_name(i_name)
69
        j.wont_be :nil?
70
        new_jenkins_home = j.jenkins_home << "/subfolder"
71
        k = JenkinsInstance.update(j.id, :jenkins_home => new_jenkins_home)
72
        k.jenkins_home.must_equal new_jenkins_home
73
      end
74

  
75

  
76
    end
77

  
78

  
79
  end
80
end
test/unit/jenkins_instance_test.rb
1
require 'foreman_pipeline_plugin_test_helper'
2

  
3
class JenkinsInstanceTest < ActiveSupport::TestCase
4

  
5
  def setup
6
    @org = get_organization
7
    @valid_url = "http://somewhere.com:8080"
8
    @valid_home = "/var/lib/jenkins"
9
    @valid_cert_path = "/home/user/.ssh/foreman-jenkins"
10
  end
11

  
12
  test "should be valid" do
13
    @instance = ForemanPipeline::JenkinsInstance.create(:name => "test_jenkins_instance",
14
                                                        :url => @valid_url,
15
                                                        :cert_path => @valid_cert_path,
16
                                                        :jenkins_home => @valid_home,
17
                                                        :organization_id => @org.id)
18
    assert @instance.errors.empty?
19
  end
20

  
21
  test "should have url" do
22
    @instance = ForemanPipeline::JenkinsInstance.create(:name => "test_jenkins_instance",
23
                                                        :url => "invalid url",
24
                                                        :cert_path => @valid_cert_path,
25
                                                        :jenkins_home => @valid_home,
26
                                                        :organization_id => @org.id)
27
    refute @instance.errors.empty?
28
  end
29

  
30

  
31
end

Also available in: Unified diff