Skip to content

Commit

Permalink
add: nproc command with test cases to system core module
Browse files Browse the repository at this point in the history
  • Loading branch information
rmammina committed Jan 20, 2022
1 parent 0715a73 commit 53995e9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Kanrisuru 0.17.0 (January 20, 2022) ##
* Add `nproc` command with test cases.

## Kanrisuru 0.16.17 (January 10, 2022) ##
* Add additional options to `wget` command.
* Rename some options to better reflect options from wget program.
Expand Down
2 changes: 1 addition & 1 deletion lib/kanrisuru/core/mount/commands/umount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def umount(opts = {})

command.append_flag('-l', opts[:lazy])
command.append_flag('-f', opts[:force])

command.append_flag('--all-targets', opts[:all_targets])
command.append_flag('--recursive', opts[:recursive])

Expand Down
1 change: 1 addition & 0 deletions lib/kanrisuru/core/system/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require_relative 'commands/load_env'
require_relative 'commands/lscpu'
require_relative 'commands/lsof'
require_relative 'commands/nproc'
require_relative 'commands/poweroff'
require_relative 'commands/ps'
require_relative 'commands/reboot'
Expand Down
15 changes: 15 additions & 0 deletions lib/kanrisuru/core/system/commands/nproc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Kanrisuru
module Core
module System
def nproc(opts = {})
command = Kanrisuru::Command.new('nproc')
command.append_flag('--all', opts[:all])
execute_shell(command)

Kanrisuru::Result.new(command, &:to_i)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/kanrisuru/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Kanrisuru
VERSION = '0.16.17'
VERSION = '0.17.0'
end
5 changes: 5 additions & 0 deletions spec/functional/core/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
end.to raise_error(ArgumentError)
end

it 'prepares nproc command' do
expect_command(host.nproc, 'nproc')
expect_command(host.nproc(all: true), 'nproc --all')
end

it 'prepares uptime command' do
expect_command(host.uptime, 'cat /proc/uptime')
end
Expand Down
8 changes: 4 additions & 4 deletions spec/functional/core/transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,23 @@
"wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random --https-only #{url}")

## FTP
expect_command(host.wget("ftp.example.com",
expect_command(host.wget('ftp.example.com',
ftp_user: 'admin',
ftp_password: '12345678',
no_remove_listing: true,
no_glob: true,
no_passive_ftp: true,
retr_symlinks: true,
preserve_permissions: true),
"wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks --preserve-permissions ftp.example.com")
'wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks --preserve-permissions ftp.example.com')

expect_command(host.wget("ftps.example.com",
expect_command(host.wget('ftps.example.com',
ftp_user: 'admin',
ftp_password: '12345678',
ftps_implicit: true,
no_ftps_resume_ssl: true,
ftps_fallback_to_ftp: true,
ftps_clear_data_connection: true), "wget --ftp-user admin --ftp-password 12345678 --ftps-implicit --no-ftps-resume-ssl --ftps-clear-data-connection --ftps-fallback-to-ftp ftps.example.com")
ftps_clear_data_connection: true), 'wget --ftp-user admin --ftp-password 12345678 --ftps-implicit --no-ftps-resume-ssl --ftps-clear-data-connection --ftps-fallback-to-ftp ftps.example.com')

## Recursive Retrieval
expect_command(host.wget(url,
Expand Down
6 changes: 6 additions & 0 deletions spec/support/shared_examples/integration/core/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
expect(result).to be_success
end

it 'gets nproc count' do
result = host.nproc
expect(result).to be_success
expect(result.to_i).to be > 0
end

it 'gets process details' do
result = host.ps

Expand Down
1 change: 1 addition & 0 deletions spec/unit/core/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
expect(host).to respond_to(:kernel_statistics)
expect(host).to respond_to(:kstat)
expect(host).to respond_to(:lsof)
expect(host).to respond_to(:nproc)
expect(host).to respond_to(:last)
expect(host).to respond_to(:uptime)
expect(host).to respond_to(:w)
Expand Down

0 comments on commit 53995e9

Please sign in to comment.