Project

General

Profile

Download (2.27 KB) Statistics
| Branch: | Tag: | Revision:

foreman_pipeline / spec / models / jenkins_instance_spec.rb @ be52ca64

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