Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u3d/installer: hard fail if we ask for a non existant package (Related to #138) #140

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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