From 0b86a89b4ca411350d9fc2d5fc04dda44cad3299 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 30 Jan 2020 12:34:17 -0800 Subject: [PATCH 1/4] Added friendly #to_s and #inspect to Platforms::Common and BaseConnection. This is a big pet peeve while debugging resources in inspec. Lots of noise, zero insight. This provides exactly the info we need for connections and platforms. Signed-off-by: Ryan Davis --- lib/train/platforms/common.rb | 9 +++++++++ lib/train/plugins/base_connection.rb | 6 +++++- test/unit/file/local_test.rb | 4 ++++ test/unit/platforms/platform_test.rb | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/train/platforms/common.rb b/lib/train/platforms/common.rb index fb68e5f3..bb55450e 100644 --- a/lib/train/platforms/common.rb +++ b/lib/train/platforms/common.rb @@ -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 diff --git a/lib/train/plugins/base_connection.rb b/lib/train/plugins/base_connection.rb index 6b0785f4..d1f3413f 100644 --- a/lib/train/plugins/base_connection.rb +++ b/lib/train/plugins/base_connection.rb @@ -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! diff --git a/test/unit/file/local_test.rb b/test/unit/file/local_test.rb index 41dcf775..8e6e2d84 100644 --- a/test/unit/file/local_test.rb +++ b/test/unit/file/local_test.rb @@ -29,6 +29,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 diff --git a/test/unit/platforms/platform_test.rb b/test/unit/platforms/platform_test.rb index c7b8d20e..2a7bbee7 100644 --- a/test/unit/platforms/platform_test.rb +++ b/test/unit/platforms/platform_test.rb @@ -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) } From 9e7f044d5d4089fdc3535b9ecf6896b806125d1f Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 30 Jan 2020 12:35:36 -0800 Subject: [PATCH 2/4] Clean up tests. 1. There is zero need to meta-program in our tests, so no Class.new unless there is a good reason. 2. We don't need to create a new connection each time (VERY HEAVY) for simple unit tests. This drops full test runs down to < 1s. Signed-off-by: Ryan Davis --- test/unit/file/local/unix_test.rb | 17 ++++++++++------- test/unit/file/local_test.rb | 5 +++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/unit/file/local/unix_test.rb b/test/unit/file/local/unix_test.rb index d9426a0a..8ec80dab 100644 --- a/test/unit/file/local/unix_test.rb +++ b/test/unit/file/local/unix_test.rb @@ -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 } @@ -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 } @@ -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 diff --git a/test/unit/file/local_test.rb b/test/unit/file/local_test.rb index 8e6e2d84..4ca5d5e6 100644 --- a/test/unit/file/local_test.rb +++ b/test/unit/file/local_test.rb @@ -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 From b5b16644d6e137080097046908ffda589b437f1a Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 30 Jan 2020 12:59:05 -0800 Subject: [PATCH 3/4] Exclude team members from PR template Signed-off-by: Ryan Davis --- .expeditor/config.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 80b7f753..308a11b3 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -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 From 41b0aa111ad6f508803d2f6d8bb41adc5cd8d0a2 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 30 Jan 2020 13:19:11 -0800 Subject: [PATCH 4/4] More yamllint fixes. Whitespace only Signed-off-by: Ryan Davis --- .expeditor/verify.pipeline.yml | 91 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 619c9e45..d42e77ae 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -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"]