-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1948 from cmcramer/master
Add Faker::Computer
- Loading branch information
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class Computer < Base | ||
class << self | ||
## | ||
# Produces the name of a computer platform. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Computer.platform #=> "Linux" | ||
# | ||
# @faker.version next | ||
def platform | ||
fetch('computer.platform') | ||
end | ||
|
||
## | ||
# Produces the name of a computer type. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Computer.type #=> "server" | ||
# | ||
# @faker.version next | ||
def type | ||
fetch('computer.type') | ||
end | ||
|
||
## | ||
# Produces the name of a computer os. | ||
# | ||
# @param platform [String] optionally specify the platform | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Computer.os #=> "RHEL 6.10" | ||
# | ||
# @faker.version next | ||
def os(platform:) | ||
platform = self.platform unless fetch_all('computer.platform').include?(platform) | ||
platform = search_format(platform) | ||
fetch("computer.#{platform}.os") | ||
end | ||
|
||
## | ||
# Produces a string with computer platform and os | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Computer.stack #=> "Linux, RHEL 6.10" | ||
# | ||
# @faker.version next | ||
def stack | ||
platform = self.platform | ||
os = fetch("computer.os.#{platform.downcase}") | ||
"#{platform}, #{os}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
en: | ||
faker: | ||
computer: | ||
type: | ||
- server | ||
- workstation | ||
platform: | ||
- Linux | ||
- macOS | ||
- Windows | ||
os: | ||
linux: | ||
- RHEL 6.10 | ||
- RHEL 7.7 | ||
- CentOS 8 | ||
- CentOS 7 | ||
- CentOS 6 | ||
- Debian 10.10.3 | ||
- Debian 9.9.10 | ||
- Ubuntu Server 18.04 | ||
- Ubuntu Server 19.10 | ||
- ArchLinux 2020.02.01 | ||
- openSUSE Leap 15.1 | ||
- Ubuntu Desktop 18.04 | ||
- Ubuntu Desktop 19.10 | ||
macos: | ||
- Catalina (10.15) | ||
- Mojave (10.14) | ||
- High Sierra (10.13) | ||
windows: | ||
- Windows 10 | ||
- Windows 8.1 | ||
- Windows 7 | ||
- Windows Server 2019 | ||
- Windows Server 2016 | ||
- Windows Server 2012 R2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
class TestFakerComputer < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Computer | ||
@platforms = Faker::Base.fetch_all('computer.platform') | ||
end | ||
|
||
def test_type | ||
assert @tester.type.match(/\w+/) | ||
end | ||
|
||
def test_platform | ||
assert @tester.platform.match(/(\w+ ?){1,3}/) | ||
end | ||
|
||
def test_stack | ||
# puts @tester.stack | ||
assert stack = @tester.stack | ||
.match(/\A(?<platform>([[:alnum:]]+\s?){1,5}), (?<os>([[:alnum:]]+-?.?\)?\(?\s?){1,5})\z/) | ||
|
||
platform = stack[:platform] | ||
search_format_platform = platform.downcase | ||
os = stack[:os] | ||
|
||
oses = Faker::Base.fetch_all("computer.os.#{search_format_platform}") | ||
|
||
assert @platforms.include?(platform) | ||
assert oses.include?(os) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters