@@ -157,17 +157,31 @@ class CodeDeployPluginInstallerTest < InstanceAgentTestCase
157157 end
158158 end
159159
160- should "generate a copy command if the file already exists and @file_exists_behavior is set to 'OVERWRITE'" do
161- @app_spec
162- . stubs ( :files )
163- . returns ( [ stub ( :source => "src1" ,
164- :destination => "dst1" ) ] )
165- File . stubs ( :exists? ) . with ( "dst1/src1" ) . returns ( true )
166- @instruction_builder
167- . expects ( :copy )
168- . with ( "deploy-archive-dir/src1" , "dst1/src1" )
169- @installer . file_exists_behavior = "OVERWRITE"
170- @installer . install ( @deployment_group_id , @app_spec )
160+ context "if the file already exists and @file_exists_behavior is set to 'OVERWRITE'" do
161+ setup do
162+ @app_spec
163+ . stubs ( :files )
164+ . returns ( [ stub ( :source => "src1" ,
165+ :destination => "dst1" ) ] )
166+ File . stubs ( :exists? ) . with ( "dst1/src1" ) . returns ( true )
167+ @installer . file_exists_behavior = "OVERWRITE"
168+ end
169+
170+ should "generate a copy command if destination is regular file" do
171+ File . stubs ( :directory? ) . with ( "dst1/src1" ) . returns ( false )
172+ @instruction_builder
173+ . expects ( :copy )
174+ . with ( "deploy-archive-dir/src1" , "dst1/src1" )
175+ @installer . install ( @deployment_group_id , @app_spec )
176+ end
177+
178+ should "raise an error if destination is directory" do
179+ File . stubs ( :directory? ) . with ( "dst1/src1" ) . returns ( true )
180+ File . stubs ( :symlink? ) . with ( "dst1/src1" ) . returns ( false )
181+ assert_raised_with_message ( "The deployment failed because a directory already exists at this location: dst1/src1" ) do
182+ @installer . install ( @deployment_group_id , @app_spec )
183+ end
184+ end
171185 end
172186
173187 should "neither generate a copy command nor raise an error if the file already exists and @file_exists_behavior is set to 'RETAIN'" do
0 commit comments