Skip to content

Commit 2ff28c3

Browse files
authored
adding folder_privacy violation (#53)
1 parent a7c68f6 commit 2ff28c3

4 files changed

Lines changed: 52 additions & 4 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pack_stats (0.2.0)
4+
pack_stats (0.2.1)
55
code_ownership
66
code_teams
77
dogapi

lib/pack_stats/private/metrics/packwerk_checker_usage.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def violation_type_tag
3838
CHECKERS = T.let([
3939
PackwerkChecker.new(key: 'enforce_dependencies', violation_type: 'dependency', direction: Direction::Outbound),
4040
PackwerkChecker.new(key: 'enforce_privacy', violation_type: 'privacy', direction: Direction::Inbound),
41+
PackwerkChecker.new(key: 'enforce_folder_privacy', violation_type: 'folder_privacy', direction: Direction::Inbound),
4142
PackwerkChecker.new(key: 'enforce_layers', violation_type: 'layer', direction: Direction::Outbound),
4243
PackwerkChecker.new(key: 'enforce_visibility', violation_type: 'visibility', direction: Direction::Outbound),
4344
], T::Array[PackwerkChecker])

pack_stats.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'pack_stats'
3-
spec.version = '0.2.0'
3+
spec.version = '0.2.1'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['dev@gusto.com']
66

spec/pack_stats_spec.rb

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
142142
end
143143
end
144144

145-
context 'in app that does not use package protectiosn with a simple package owned by one team' do
145+
context 'in app that does not use package protection with a simple package owned by one team' do
146146
include_context 'only one team'
147147

148148
before do
@@ -981,7 +981,7 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
981981
expect(metrics).to include_metric GaugeMetric.new(name: 'modularization.by_package.public_files.count', count: 0, tags: Tags.for(['package:packs/only_package', 'app:MyApp', 'team:Unknown', 'max_enforcements:true'])) end
982982
end
983983

984-
context 'in app with architectural enforcements' do
984+
context 'in app with layer enforcements' do
985985
before do
986986
write_file('config/teams/Foo Team.yml', <<~CONTENTS)
987987
name: Foo Team
@@ -1048,6 +1048,53 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
10481048
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'other_team:Foo Team', 'violation_type:visibility']))
10491049
end
10501050
end
1051+
1052+
context 'in app with folder_privacy enforcements' do
1053+
before do
1054+
write_file('config/teams/Foo Team.yml', <<~CONTENTS)
1055+
name: Foo Team
1056+
CONTENTS
1057+
1058+
write_file('config/teams/Bar Team.yml', <<~CONTENTS)
1059+
name: Bar Team
1060+
CONTENTS
1061+
1062+
write_file('packs/my_pack/package.yml', <<~CONTENTS)
1063+
enforce_dependencies: false
1064+
enforce_privacy: false
1065+
enforce_folder_privacy: true
1066+
enforce_visibility: true
1067+
layer: utilities
1068+
metadata:
1069+
owner: Bar Team
1070+
CONTENTS
1071+
1072+
write_file('packs/other_pack/package.yml', <<~CONTENTS)
1073+
enforce_dependencies: false
1074+
metadata:
1075+
owner: Foo Team
1076+
CONTENTS
1077+
1078+
write_file('packs/my_pack/package_todo.yml', <<~CONTENTS)
1079+
---
1080+
packs/other_pack:
1081+
"SomeConstant":
1082+
violations:
1083+
- folder_privacy
1084+
- visibility
1085+
files:
1086+
- some_file.rb
1087+
CONTENTS
1088+
1089+
end
1090+
1091+
it 'emits the right metrics' do
1092+
expect(metrics).to include_metric GaugeMetric.for('all_packages.packwerk_checkers.strict.count', 0, Tags.for(['app:MyApp', 'violation_type:folder_privacy']))
1093+
expect(metrics).to include_metric GaugeMetric.for('all_packages.packwerk_checkers.true.count', 1, Tags.for(['app:MyApp', 'violation_type:folder_privacy']))
1094+
expect(metrics).to include_metric GaugeMetric.for('all_packages.violations.count', 1, Tags.for(['app:MyApp', 'violation_type:folder_privacy']))
1095+
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'violation_type:folder_privacy']))
1096+
end
1097+
end
10511098
end
10521099
end
10531100
end

0 commit comments

Comments
 (0)