Skip to content

Commit 215f018

Browse files
author
nyo
committed
Added cli-validator tests
1 parent 6a96bb5 commit 215f018

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/aws/codedeploy/local/cli_validator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ def validate(args)
4040
end
4141

4242
if (type == 'directory' && (uri.scheme != 'https' && uri.scheme != 's3' && File.directory?(location)))
43-
unless File.exists? "#{location}/appspec.yml"
44-
raise ValidationError.new("Expecting appspec file at location #{location}/appspec.yml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml file or specify a bundle location containing an appspec.yml file in its root directory")
43+
appspec_filename = args['--appspec-filename']
44+
if !appspec_filename.nil? && !File.exists?("#{location}/#{appspec_filename}")
45+
raise ValidationError.new("Expecting appspec file at location #{location}/#{appspec_filename} but it is not found there. Please either run the CLI from within a directory containing the #{appspec_filename} file or specify a bundle location containing an #{appspec_filename} file in its root directory")
46+
end
47+
if !File.exists?("#{location}/appspec.yml") && !File.exists?("#{location}/appspec.yaml")
48+
raise ValidationError.new("Expecting appspec file at location #{location}/appspec.yml or #{location}/appspec.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml or appspec.yaml file or specify a bundle location containing an appspec.yml or appspec.yaml file in its root directory")
4549
end
4650
end
4751

@@ -60,7 +64,7 @@ def validate(args)
6064
end
6165

6266
def any_new_revision_event_or_install_before_download_bundle(events)
63-
events_using_new_revision.push('Install').any? do |event_not_allowed_before_download_bundle|
67+
events_using_new_revision.push('Install').any? do |event_not_allowed_before_download_bundle|
6468
events.take_while{|e| e != 'DownloadBundle'}.include? event_not_allowed_before_download_bundle
6569
end
6670
end

spec/aws/codedeploy/local/cli_validator_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,23 @@
9696
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
9797
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
9898
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(false)
99-
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "Expecting appspec file at location #{FAKE_DIRECTORY}/appspec.yml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml file or specify a bundle location containing an appspec.yml file in its root directory")
99+
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yaml").and_return(false)
100+
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "Expecting appspec file at location #{FAKE_DIRECTORY}/appspec.yml or #{FAKE_DIRECTORY}/appspec.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml or appspec.yaml file or specify a bundle location containing an appspec.yml or appspec.yaml file in its root directory")
101+
end
102+
end
103+
104+
context 'when loction is directory and --appspec-filename is specified (but not existing)' do
105+
let(:args) do
106+
{"--bundle-location"=>FAKE_DIRECTORY,
107+
"--type"=>'directory',
108+
"--appspec-filename"=>"appspec-override.yaml"}
109+
end
110+
111+
it 'throws a ValidationError' do
112+
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
113+
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
114+
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec-override.yaml").and_return(false)
115+
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "Expecting appspec file at location #{FAKE_DIRECTORY}/appspec-override.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec-override.yaml file or specify a bundle location containing an appspec-override.yaml file in its root directory")
100116
end
101117
end
102118

@@ -225,7 +241,7 @@
225241
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
226242
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
227243
expect(validator.validate(args)).to equal(args)
228-
end
244+
end
229245
end
230246
end
231247
end

0 commit comments

Comments
 (0)