Skip to content

Commit

Permalink
Merge pull request #565 from inspec/zenspider/inspect
Browse files Browse the repository at this point in the history
Improve debugging experience by making platform and connection less noisy.
  • Loading branch information
Ryan Davis authored Feb 3, 2020
2 parents 83885ad + 41b0aa1 commit 4f42b09
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 57 deletions.
5 changes: 4 additions & 1 deletion .expeditor/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ merge_actions:
subscriptions:
- workload: pull_request_opened:{{agent_id}}:*
actions:
- post_github_comment:.expeditor/templates/pull_request.mustache
- post_github_comment:.expeditor/templates/pull_request.mustache:
ignore_team_members:
- inspec/owners
- inspec/inspec-core-team
- built_in:github_auto_assign_author:
only_if_team_member:
- inspec/owners
Expand Down
91 changes: 45 additions & 46 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
---
steps:

- label: lint-ruby-2.6
command:
- RAKE_TASK=lint /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.6
- label: lint-ruby-2.6
command:
- RAKE_TASK=lint /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.6

- label: run-tests-ruby-2.4
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.4
- label: run-tests-ruby-2.4
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.4

- label: run-tests-ruby-2.5
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.5
- label: run-tests-ruby-2.5
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.5

- label: run-tests-ruby-2.6
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.6
- label: run-tests-ruby-2.6
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.6

- label: run-tests-ruby-2.7
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.7

- label: run-tests-ruby-2.6-windows
command:
- /workdir/.expeditor/buildkite/verify.ps1
expeditor:
executor:
docker:
environment:
- BUILDKITE
host_os: windows
shell: ["powershell", "-Command"]
- label: run-tests-ruby-2.7
command:
- /workdir/.expeditor/buildkite/verify.sh
expeditor:
executor:
docker:
image: ruby:2.7

- label: run-tests-ruby-2.6-windows
command:
- /workdir/.expeditor/buildkite/verify.ps1
expeditor:
executor:
docker:
environment:
- BUILDKITE
host_os: windows
shell: ["powershell", "-Command"]
9 changes: 9 additions & 0 deletions lib/train/platforms/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ def detect(&block)
# TODO: detect shouldn't be a setter and getter at the same time
@detect ||= ->(_) { false }
end

def to_s
be = backend ? backend.backend_type : "unknown"
"%s:%s:%s" % [self.class, be, name]
end

def inspect
to_s
end
end
end
6 changes: 5 additions & 1 deletion lib/train/plugins/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def force_platform!(name, platform_details = nil)
plat
end

def backend_type
@options[:backend] || "unknown"
end

def inspect
"%s[%s]" % [self.class, (@options[:backend] || "Unknown")]
"%s[%s]" % [self.class, backend_type]
end

alias direct_platform force_platform!
Expand Down
17 changes: 10 additions & 7 deletions test/unit/file/local/unix_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
require "train/transports/mock"
require "train/transports/local"

class FileTester < Train::File::Local::Unix
def type
:file
end
end

describe Train::File::Local::Unix do
let(:cls) { Train::File::Local::Unix }

Expand All @@ -23,8 +29,9 @@
skip "not on windows" if windows?
end

let(:transport) { Train::Transports::Local.new }
let(:connection) { transport.connection }
# there is zero need to instantiate this OVER and over, so just do it once.
transport = Train::Transports::Local.new
connection = transport.connection

let(:stat) { Struct.new(:mode, :size, :mtime, :uid, :gid) }
let(:uid) { rand }
Expand Down Expand Up @@ -119,11 +126,7 @@ def meta_stub(method, param, &block)

describe "#unix_mode_mask" do
let(:file_tester) do
Class.new(cls) do
define_method :type do
:file
end
end.new(nil, nil, false)
FileTester.new(nil, nil, false)
end

it "check owner mode calculation" do
Expand Down
9 changes: 7 additions & 2 deletions test/unit/file/local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
require "train/transports/local"

describe Train::File::Local do
let(:transport) { Train::Transports::Local.new }
let(:connection) { transport.connection }
# there is zero need to instantiate this OVER and over, so just do it once.
transport = Train::Transports::Local.new
connection = transport.connection

it "gets file contents" do
res = rand.to_s
Expand All @@ -29,6 +30,10 @@
end
end

it "has a friendly inspect" do
_(connection.inspect).must_equal "Train::Transports::Local::Connection[unknown]"
end

describe "#type" do
it "returns the type block_device if it is block device" do
File.stub :ftype, "blockSpecial" do
Expand Down
6 changes: 6 additions & 0 deletions test/unit/platforms/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def mock_os_hierarchy(plat)
_(os.to_hash).must_equal({ family: x })
end

it "has a friendly #to_s and #inspect" do
plat = mock_platform("redhat")
_(plat.to_s).must_equal "Train::Platforms::Platform:unknown:redhat"
_(plat.inspect).must_equal "Train::Platforms::Platform:unknown:redhat"
end

describe "with platform set to redhat" do
let(:os) { mock_platform("redhat") }
it { _(os.redhat?).must_equal(true) }
Expand Down

0 comments on commit 4f42b09

Please sign in to comment.