Skip to content

Commit 4f42b09

Browse files
author
Ryan Davis
authored
Merge pull request #565 from inspec/zenspider/inspect
Improve debugging experience by making platform and connection less noisy.
2 parents 83885ad + 41b0aa1 commit 4f42b09

File tree

7 files changed

+86
-57
lines changed

7 files changed

+86
-57
lines changed

.expeditor/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ merge_actions:
5252
subscriptions:
5353
- workload: pull_request_opened:{{agent_id}}:*
5454
actions:
55-
- post_github_comment:.expeditor/templates/pull_request.mustache
55+
- post_github_comment:.expeditor/templates/pull_request.mustache:
56+
ignore_team_members:
57+
- inspec/owners
58+
- inspec/inspec-core-team
5659
- built_in:github_auto_assign_author:
5760
only_if_team_member:
5861
- inspec/owners

.expeditor/verify.pipeline.yml

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
11
---
22
steps:
33

4-
- label: lint-ruby-2.6
5-
command:
6-
- RAKE_TASK=lint /workdir/.expeditor/buildkite/verify.sh
7-
expeditor:
8-
executor:
9-
docker:
10-
image: ruby:2.6
4+
- label: lint-ruby-2.6
5+
command:
6+
- RAKE_TASK=lint /workdir/.expeditor/buildkite/verify.sh
7+
expeditor:
8+
executor:
9+
docker:
10+
image: ruby:2.6
1111

12-
- label: run-tests-ruby-2.4
13-
command:
14-
- /workdir/.expeditor/buildkite/verify.sh
15-
expeditor:
16-
executor:
17-
docker:
18-
image: ruby:2.4
12+
- label: run-tests-ruby-2.4
13+
command:
14+
- /workdir/.expeditor/buildkite/verify.sh
15+
expeditor:
16+
executor:
17+
docker:
18+
image: ruby:2.4
1919

20-
- label: run-tests-ruby-2.5
21-
command:
22-
- /workdir/.expeditor/buildkite/verify.sh
23-
expeditor:
24-
executor:
25-
docker:
26-
image: ruby:2.5
20+
- label: run-tests-ruby-2.5
21+
command:
22+
- /workdir/.expeditor/buildkite/verify.sh
23+
expeditor:
24+
executor:
25+
docker:
26+
image: ruby:2.5
2727

28-
- label: run-tests-ruby-2.6
29-
command:
30-
- /workdir/.expeditor/buildkite/verify.sh
31-
expeditor:
32-
executor:
33-
docker:
34-
image: ruby:2.6
28+
- label: run-tests-ruby-2.6
29+
command:
30+
- /workdir/.expeditor/buildkite/verify.sh
31+
expeditor:
32+
executor:
33+
docker:
34+
image: ruby:2.6
3535

36-
- label: run-tests-ruby-2.7
37-
command:
38-
- /workdir/.expeditor/buildkite/verify.sh
39-
expeditor:
40-
executor:
41-
docker:
42-
image: ruby:2.7
43-
44-
- label: run-tests-ruby-2.6-windows
45-
command:
46-
- /workdir/.expeditor/buildkite/verify.ps1
47-
expeditor:
48-
executor:
49-
docker:
50-
environment:
51-
- BUILDKITE
52-
host_os: windows
53-
shell: ["powershell", "-Command"]
36+
- label: run-tests-ruby-2.7
37+
command:
38+
- /workdir/.expeditor/buildkite/verify.sh
39+
expeditor:
40+
executor:
41+
docker:
42+
image: ruby:2.7
5443

44+
- label: run-tests-ruby-2.6-windows
45+
command:
46+
- /workdir/.expeditor/buildkite/verify.ps1
47+
expeditor:
48+
executor:
49+
docker:
50+
environment:
51+
- BUILDKITE
52+
host_os: windows
53+
shell: ["powershell", "-Command"]

lib/train/platforms/common.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@ def detect(&block)
2424
# TODO: detect shouldn't be a setter and getter at the same time
2525
@detect ||= ->(_) { false }
2626
end
27+
28+
def to_s
29+
be = backend ? backend.backend_type : "unknown"
30+
"%s:%s:%s" % [self.class, be, name]
31+
end
32+
33+
def inspect
34+
to_s
35+
end
2736
end
2837
end

lib/train/plugins/base_connection.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ def force_platform!(name, platform_details = nil)
107107
plat
108108
end
109109

110+
def backend_type
111+
@options[:backend] || "unknown"
112+
end
113+
110114
def inspect
111-
"%s[%s]" % [self.class, (@options[:backend] || "Unknown")]
115+
"%s[%s]" % [self.class, backend_type]
112116
end
113117

114118
alias direct_platform force_platform!

test/unit/file/local/unix_test.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
require "train/transports/mock"
44
require "train/transports/local"
55

6+
class FileTester < Train::File::Local::Unix
7+
def type
8+
:file
9+
end
10+
end
11+
612
describe Train::File::Local::Unix do
713
let(:cls) { Train::File::Local::Unix }
814

@@ -23,8 +29,9 @@
2329
skip "not on windows" if windows?
2430
end
2531

26-
let(:transport) { Train::Transports::Local.new }
27-
let(:connection) { transport.connection }
32+
# there is zero need to instantiate this OVER and over, so just do it once.
33+
transport = Train::Transports::Local.new
34+
connection = transport.connection
2835

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

120127
describe "#unix_mode_mask" do
121128
let(:file_tester) do
122-
Class.new(cls) do
123-
define_method :type do
124-
:file
125-
end
126-
end.new(nil, nil, false)
129+
FileTester.new(nil, nil, false)
127130
end
128131

129132
it "check owner mode calculation" do

test/unit/file/local_test.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
require "train/transports/local"
33

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

89
it "gets file contents" do
910
res = rand.to_s
@@ -29,6 +30,10 @@
2930
end
3031
end
3132

33+
it "has a friendly inspect" do
34+
_(connection.inspect).must_equal "Train::Transports::Local::Connection[unknown]"
35+
end
36+
3237
describe "#type" do
3338
it "returns the type block_device if it is block device" do
3439
File.stub :ftype, "blockSpecial" do

test/unit/platforms/platform_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def mock_os_hierarchy(plat)
112112
_(os.to_hash).must_equal({ family: x })
113113
end
114114

115+
it "has a friendly #to_s and #inspect" do
116+
plat = mock_platform("redhat")
117+
_(plat.to_s).must_equal "Train::Platforms::Platform:unknown:redhat"
118+
_(plat.inspect).must_equal "Train::Platforms::Platform:unknown:redhat"
119+
end
120+
115121
describe "with platform set to redhat" do
116122
let(:os) { mock_platform("redhat") }
117123
it { _(os.redhat?).must_equal(true) }

0 commit comments

Comments
 (0)