Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 141 lines (124 sloc) 5.023 kb
3f1d743 @adamhjk Updating the license, removing the spec reports
adamhjk authored
1 #
2 # Author:: Adam Jacob (<adam@opscode.com>)
3 # Copyright:: Copyright (c) 2011 Opscode, Inc.
4 # License:: Apache License, Version 2.0
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
5979a58 @adamhjk Initial commit to chef-jenkins.
adamhjk authored
19 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
20
eca356f @adamhjk lets try some grit
adamhjk authored
21 describe "Chef::Jenkins" do
22 before(:each) do
b0cc1b6 Automated patch level updates
Jenkins authored
23 AH.reset!
24 Chef::Config.from_file(AH.file("config.rb"))
175150c Working sync functionality
Jenkins CI authored
25 @cj = Chef::Jenkins.new
eca356f @adamhjk lets try some grit
adamhjk authored
26 end
27
28 describe "initialize" do
175150c Working sync functionality
Jenkins CI authored
29 it "returns a Chef::Jenkins object" do
eca356f @adamhjk lets try some grit
adamhjk authored
30 @cj.should be_a_kind_of(Chef::Jenkins)
31 end
175150c Working sync functionality
Jenkins CI authored
32
33 it "sets the user.name git config variable" do
34 @cj.git.config["user.name"].should == Chef::Config[:jenkins][:git_user]
35 end
36
37 it "sets the user.email git config variable" do
38 @cj.git.config["user.email"].should == Chef::Config[:jenkins][:git_email]
39 end
eca356f @adamhjk lets try some grit
adamhjk authored
40 end
41
70d05aa @adamhjk Adding bump patch levels, inflight assets
adamhjk authored
42 describe "bump_patch_level" do
175150c Working sync functionality
Jenkins CI authored
43 it "updates metadata.rb to have an incremented patch version" do
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
44 @cj.bump_patch_level(AH.file("metadata.rb"), "ntp")
70d05aa @adamhjk Adding bump patch levels, inflight assets
adamhjk authored
45 has_correct_version = false
46 IO.foreach(AH.file("metadata.rb")) do |line|
47 if line =~ /^version '0\.99\.5'$/
48 has_correct_version = true
49 break
50 end
51 end
52 has_correct_version.should == true
53 end
5979a58 @adamhjk Initial commit to chef-jenkins.
adamhjk authored
54 end
175150c Working sync functionality
Jenkins CI authored
55
56 describe "write_current_commit" do
57 it "writes the current commit out to a file" do
58 @cj.write_current_commit(AH::INFLIGHT)
59 cfile = File.join(AH::INFLIGHT, ".chef_jenkins_last_commit")
60 File.exists?(cfile).should == true
61 # The length of a shasum
62 IO.read(cfile).length.should == 40
63 end
64 end
65
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
66 describe "commit_cookbook_changes" do
175150c Working sync functionality
Jenkins CI authored
67 it "commits changes to git, with the number and list of cookbooks" do
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
68 cookbook_list = [ "ntp" ]
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
69 cr = "\n"
175150c Working sync functionality
Jenkins CI authored
70 @cj.git.stub!(:commit).and_return(true)
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
71 @cj.git.should_receive(:commit).with("1 cookbooks patch levels updated by Chef Jenkins\n\n#{cookbook_list.join(cr)}", :add_all => true)
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
72 @cj.commit_cookbook_changes(cookbook_list)
175150c Working sync functionality
Jenkins CI authored
73 end
74 end
75
76 describe "read_last_commit" do
77 it "returns the last commit" do
78 @cj.write_current_commit(AH::INFLIGHT)
79 @cj.read_last_commit(AH::INFLIGHT).length.should == 40
80 end
81 end
82
83 describe "integration_branch_name" do
84 it "uses the BUILD_TAG environment variable if it is set" do
85 ENV['BUILD_TAG'] = "snoopy"
86 @cj.integration_branch_name.should == "snoopy"
87 end
88
89 it "sets a manual build tag with the number of seconds since the epoch if no environment value is set" do
90 ENV.delete('BUILD_TAG')
91 @cj.integration_branch_name.should =~ /^chef-jenkins-manual-\d+$/
92 end
93 end
94
95 describe "find_changed_cookbooks" do
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
96 it "prints a list of cookbooks changed since last commit" do
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
97 system("echo '#test' >> #{AH::INFLIGHT}/cookbooks/ntp/metadata.rb")
98 system("cd #{AH::INFLIGHT}; git commit -am 'changed cookbook ntp';")
53f94a6 command line option fixes
Jenkins CI authored
99 changed_list, deleted_list = @cj.find_changed_cookbooks('HEAD^', 'HEAD', ["#{AH::INFLIGHT}/cookbooks"])
100 changed_list.include?("ntp").should == true
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
101 end
102 end
103
104 describe "find_changed_roles" do
105 it "prints a list of roles changed since last commit" do
106 system("echo '#test' >> #{AH::INFLIGHT}/roles/apache2.rb")
107 system("echo '#test' >> #{AH::INFLIGHT}/roles/vagrant.rb")
108 system("cd #{AH::INFLIGHT}; git commit -am 'changed 2 roles';")
53f94a6 command line option fixes
Jenkins CI authored
109 role_list, deleted_list = @cj.find_changed_roles('HEAD^', 'HEAD', ["#{AH::INFLIGHT}/roles"])
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
110 role_list = role_list.map {|i| File.basename(i)}
111 role_list.include?("apache2.rb").should == true
112 role_list.include?("vagrant.rb").should == true
175150c Working sync functionality
Jenkins CI authored
113 end
114 end
70d05aa @adamhjk Adding bump patch levels, inflight assets
adamhjk authored
115
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
116 describe "find_changed_data_bags" do
117 it "prints a list of data_bags changed since last commit" do
118 system("echo '#test' >> #{AH::INFLIGHT}/data_bags/users/foobar.json")
119 system("echo '#test' >> #{AH::INFLIGHT}/data_bags/groups/ops.json")
120 system("cd #{AH::INFLIGHT}; git commit -am 'changed 2 databags';")
53f94a6 command line option fixes
Jenkins CI authored
121 data_bag_list, deleted_list = @cj.find_changed_data_bags('HEAD^', 'HEAD', ["#{AH::INFLIGHT}/data_bags"])
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
122 data_bag_list = data_bag_list.map {|i| File.basename(i)}
123 data_bag_list.include?("foobar.json").should == true
124 data_bag_list.include?("ops.json").should == true
125 end
126 end
127
128 describe "knife cookbook test" do
129 it "test cookbook(s) with knife cookbook test" do
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
130 @cj.knife_cookbook_test(["ntp"])
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
131 end
132 end
133
134 describe "foodcritic test" do
225df5d spec assets changes; require foodcritic only when -t provided
Ruoran Wang authored
135 require "foodcritic"
136 it "test cookbook(s) with foodcritic" do
137 @cj.foodcritic_test(["ntp"])
90caf24 rspec test cases for new functions, with dummy files to test
Jenkins CI authored
138 end
139 end
140 end
Something went wrong with that request. Please try again.