-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check require encapsulation of components #3646
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check require encapsulation | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**" | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ master ] | ||
|
||
jobs: | ||
check-require-encapsulation: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.2' | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
- run: rm -f .rspec | ||
- run: bundle exec rspec spec/require_encapsulation_check.rb | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../tracing/contrib' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this |
||
require_relative '../integration' | ||
|
||
require_relative 'patcher' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
require_relative 'gateway/route_params' | ||
require_relative 'gateway/request' | ||
require_relative '../../../tracing/contrib/sinatra/framework' | ||
require_relative '../../../tracing/contrib' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good catch! But |
||
|
||
module Datadog | ||
module AppSec | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'English' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filename should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's in order to have |
||
REQUIRES = %w[ | ||
datadog/appsec | ||
datadog/core | ||
datadog/kit | ||
datadog/profiling | ||
datadog/tracing | ||
].freeze | ||
Comment on lines
+2
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constant will be leaking globally, as is it should probably go into the Could even be a plain local variable, or even just |
||
|
||
RSpec.describe 'require encapsulation' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a way I feel this description isn't quite correct, which led me to think that this spec isn't quite how we expect it to be. Notably it puts some cross-component knowledge into that spec file. I think it might be better if each "require "works is isolated in each separate component:
|
||
before(:all) do | ||
# Permit Datadog::VERSION to be defined but no other constants. | ||
# See the note in gemspec about requiring 'datadog/version'. | ||
expect(defined?(Datadog)).to eq 'constant' | ||
expect(Datadog.constants).to eq([:VERSION]) | ||
end | ||
|
||
REQUIRES.each do |req| | ||
context req do | ||
it 'loads' do | ||
pid = fork do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
require req | ||
exec('true') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you tricky ;) |
||
end | ||
|
||
Process.waitpid(pid) | ||
expect($CHILD_STATUS.exitstatus).to be 0 | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for a separate job?
If the file is named correctly it can be part of the usual
rake spec
tasks and tested across the matrix.