1+ #
2+ # Author:: Daniel DeLeo (<dan@kallistec.com>)
3+ # Copyright:: Copyright (c) 2008 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+
19+ require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , ".." , "spec_helper" ) )
20+
21+ describe Chef ::Provider ::Deploy ::Revision do
22+
23+ before do
24+ Chef ::Config [ :file_cache_path ] = '/tmp/foo'
25+ @resource = Chef ::Resource ::Deploy . new ( "/my/deploy/dir" )
26+ @resource . revision ( "8a3195bf3efa246f743c5dfa83683201880f935c" )
27+ @node = Chef ::Node . new
28+ @provider = Chef ::Provider ::Deploy ::Revision . new ( @node , @resource )
29+ @provider . load_current_resource
30+ @runner = mock ( "runnah" , :null_object => true )
31+ Chef ::Runner . stub! ( :new ) . and_return ( @runner )
32+ @expected_release_dir = "/my/deploy/dir/releases/8a3195bf3efa246f743c5dfa83683201880f935c"
33+ end
34+
35+ after do
36+ # Make sure we don't keep any state in our tests
37+ FileUtils . rm_rf Chef ::FileCache . create_cache_path ( 'revision-deploys' , false )
38+ end
39+
40+
41+ it "uses the resolved revision from the SCM as the release slug" do
42+ @provider . scm_provider . stub! ( :revision_slug ) . and_return ( "uglySlugly" )
43+ @provider . send ( :release_slug ) . should == "uglySlugly"
44+ end
45+
46+ it "deploys to a dir named after the revision" do
47+ @provider . release_path . should == @expected_release_dir
48+ end
49+
50+ it "stores the release dir in the file cache when copying the cached repo" do
51+ FileUtils . stub! ( :mkdir_p )
52+ FileUtils . stub! ( :cp_r )
53+ @provider . copy_cached_repo
54+ @provider . stub! ( :release_slug ) . and_return ( "73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2" )
55+ @provider . load_current_resource
56+ @provider . copy_cached_repo
57+ second_release = "/my/deploy/dir/releases/73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2"
58+ @provider . all_releases . should == [ @expected_release_dir , second_release ]
59+ end
60+
61+ it "removes a release from the file cache when it's deleted by :cleanup!" do
62+ %w{ first second third fourth fifth latest } . each do |release_name |
63+ @provider . send ( :release_created , release_name )
64+ end
65+ @provider . all_releases . should == %w{ first second third fourth fifth latest }
66+
67+ FileUtils . stub ( :rm_rf )
68+ @provider . cleanup!
69+ @provider . all_releases . should == %w{ second third fourth fifth latest }
70+ end
71+
72+ end
0 commit comments