Skip to content

Commit

Permalink
u3d/downloader/installer: hard fail if we ask for a non existant pack…
Browse files Browse the repository at this point in the history
…age (Related to #138)
  • Loading branch information
lacostej committed Sep 13, 2017
1 parent 295aaba commit 406a973
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
8 changes: 8 additions & 0 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def install(args: [], options: {})
unity = check_unity_presence(version: version)
return unless enforce_setup_coherence(packages, options, unity, definition)

verify_package_names(definition, packages)

if options[:install]
U3d::Globals.use_keychain = true if options[:keychain] && Helper.mac?
UI.important 'Root privileges are required'
Expand Down Expand Up @@ -217,6 +219,12 @@ def release_letter_mapping

private

def verify_package_names(definition, packages)
packages.each do |package|
UI.user_error! "package '#{package}' doesn't exist" unless definition.available_package? package
end
end

def specified_or_current_project_version(version)
unless version # no version specified, use the one from the current unity project if any
UI.message "No unity version specified. If the current directory is a Unity project, we try to install the one it requires"
Expand Down
4 changes: 4 additions & 0 deletions lib/u3d/unity_version_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def available_packages
@ini.keys
end

def available_package?(p)
available_packages.include? p
end

def [](key)
return nil unless @ini
@ini[key]
Expand Down
26 changes: 14 additions & 12 deletions spec/u3d/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
in_a_project(version: '1.2.3f4')
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl')
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: ['Unity'])

expect(U3d::Downloader).to receive(:fetch_modules).with(
definition,
Expand Down Expand Up @@ -269,7 +269,7 @@
it 'resolves alias when passed as a version' do
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl')
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: ['Unity'])

expect(U3d::Downloader).to receive(:fetch_modules).with(
definition,
Expand Down Expand Up @@ -319,6 +319,7 @@
on_linux
with_fake_cache('linux' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
expect_privileges_check
expected_definition('1.2.3f4', :linux, 'fakeurl', packages: %w[Unity])

files = double('files')
expect(U3d::Downloader).to receive(:download_modules) { files }
Expand Down Expand Up @@ -370,7 +371,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_no_privileges_check
expected_definition('1.2.3f4', :fakeos, 'fakeurl')
expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: %w[packageA packageB])

expect(U3dCore::UI).to receive(:error) {}

Expand All @@ -389,7 +390,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl')
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: %w[Unity packageA packageB])

files = double('files')
expect(U3d::Downloader).to receive(:download_modules).with(
Expand Down Expand Up @@ -418,7 +419,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl')
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: %w[Unity])

files = double('files')
expect(U3d::Downloader).to receive(:download_modules).with(
Expand Down Expand Up @@ -469,9 +470,9 @@
it 'installs only uninstalled packages when packages are specified' do
on_fake_os_not_linux
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
are_installed([fake_installation('1.2.3f4', packages: ['packageA'])])
are_installed([fake_installation('1.2.3f4', packages: %w[packageA])])
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl')
definition = expected_definition('1.2.3f4', :fakeos, 'fakeurl', packages: %w[packageA packageB])

files = double("files")
expect(U3d::Downloader).to receive(:download_modules).with(
Expand Down Expand Up @@ -514,7 +515,7 @@
in_a_project(version: '1.2.3f4')
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
definition = expected_definition('1.2.3f4', :fakeos, nil)
definition = expected_definition('1.2.3f4', :fakeos, nil, packages: %w[Unity])

expect_privileges_check
expect(U3d::Downloader).to receive(:fetch_modules).with(
Expand Down Expand Up @@ -576,6 +577,7 @@
on_linux
with_fake_cache('linux' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
expect_privileges_check
expected_definition('1.2.3f4', :linux, nil, packages: %w[Unity])

files = double('files')
expect(U3d::Downloader).to receive(:fetch_modules) { files }
Expand Down Expand Up @@ -626,7 +628,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_no_privileges_check
expected_definition('1.2.3f4', :fakeos, nil)
expected_definition('1.2.3f4', :fakeos, nil, packages: %w[packageA packageB])

expect(U3dCore::UI).to receive(:error) {}

Expand All @@ -645,7 +647,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, nil)
definition = expected_definition('1.2.3f4', :fakeos, nil, packages: %w[Unity packageA packageB])

files = double("files")
expect(U3d::Downloader).to receive(:local_files).with(
Expand Down Expand Up @@ -674,7 +676,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
nothing_installed
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, nil)
definition = expected_definition('1.2.3f4', :fakeos, nil, packages: %w[Unity])

files = double('files')
expect(U3d::Downloader).to receive(:local_files).with(
Expand Down Expand Up @@ -727,7 +729,7 @@
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
are_installed([fake_installation('1.2.3f4', packages: ['packageA'])])
expect_privileges_check
definition = expected_definition('1.2.3f4', :fakeos, nil)
definition = expected_definition('1.2.3f4', :fakeos, nil, packages: %w[packageA packageB])

files = double('files')
expect(U3d::Downloader).to receive(:local_files).with(
Expand Down

0 comments on commit 406a973

Please sign in to comment.