Skip to content

Commit 7a0b10d

Browse files
author
Alex Evanczuk
committed
Move tests to own class
1 parent c21514f commit 7a0b10d

File tree

2 files changed

+93
-62
lines changed

2 files changed

+93
-62
lines changed

test/unit/application_validator_test.rb

-62
Original file line numberDiff line numberDiff line change
@@ -78,68 +78,6 @@ class ApplicationValidatorTest < Minitest::Test
7878
assert_match(/Invalid 'dependencies' option/, result.error_value)
7979
end
8080

81-
test "check_package_manifests_for_privacy returns an error for unresolvable privatized constants" do
82-
use_template(:skeleton)
83-
ConstantResolver.expects(:new).returns(stub("resolver", resolve: nil))
84-
85-
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
86-
validator.package_set,
87-
config
88-
)
89-
90-
refute result.ok?, result.error_value
91-
assert_match(
92-
/'::PrivateThing', listed in #{to_app_path('components\/timeline\/package.yml')}, could not be resolved/,
93-
result.error_value
94-
)
95-
assert_match(
96-
/Add a private_thing.rb file/,
97-
result.error_value
98-
)
99-
end
100-
101-
test "check_package_manifests_for_privacy returns an error for privatized constants in other packages" do
102-
use_template(:skeleton)
103-
context = ConstantResolver::ConstantContext.new("::PrivateThing", "private_thing.rb")
104-
105-
ConstantResolver.expects(:new).returns(stub("resolver", resolve: context))
106-
107-
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
108-
validator.package_set,
109-
config
110-
)
111-
112-
refute result.ok?, result.error_value
113-
assert_match(
114-
%r{'::PrivateThing' is declared as private in the 'components/timeline' package},
115-
result.error_value
116-
)
117-
assert_match(
118-
/but appears to be defined\sin the '.' package/,
119-
result.error_value
120-
)
121-
end
122-
123-
test "check_package_manifests_for_privacy returns an error for constants without `::` prefix" do
124-
use_template(:minimal)
125-
merge_into_app_yaml_file("package.yml", { "enforce_privacy" => ["::PrivateThing", "OtherThing"] })
126-
127-
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
128-
validator.package_set,
129-
config
130-
)
131-
132-
refute result.ok?, result.error_value
133-
assert_match(
134-
/'OtherThing', listed in the 'enforce_privacy' option in .*package.yml, is invalid./,
135-
result.error_value
136-
)
137-
assert_match(
138-
/Private constants need to be prefixed with the top-level namespace operator `::`/,
139-
result.error_value
140-
)
141-
end
142-
14381
test "check_acyclic_graph returns error when package set contains circular dependencies" do
14482
use_template(:minimal)
14583
merge_into_app_yaml_file("components/sales/package.yml", { "dependencies" => ["components/timeline"] })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "test_helper"
5+
6+
# make sure PrivateThing.constantize succeeds to pass the privacy validity check
7+
require "fixtures/skeleton/components/timeline/app/models/private_thing.rb"
8+
9+
module Packwerk
10+
class CheckPackageManifestsForPrivacyTest < Minitest::Test
11+
extend T::Sig
12+
include RailsApplicationFixtureHelper
13+
14+
setup do
15+
setup_application_fixture
16+
end
17+
18+
teardown do
19+
teardown_application_fixture
20+
end
21+
22+
test "check_package_manifests_for_privacy returns an error for unresolvable privatized constants" do
23+
use_template(:skeleton)
24+
ConstantResolver.expects(:new).returns(stub("resolver", resolve: nil))
25+
26+
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
27+
validator.package_set,
28+
config
29+
)
30+
31+
refute result.ok?, result.error_value
32+
assert_match(
33+
/'::PrivateThing', listed in #{to_app_path('components\/timeline\/package.yml')}, could not be resolved/,
34+
result.error_value
35+
)
36+
assert_match(
37+
/Add a private_thing.rb file/,
38+
result.error_value
39+
)
40+
end
41+
42+
test "check_package_manifests_for_privacy returns an error for privatized constants in other packages" do
43+
use_template(:skeleton)
44+
context = ConstantResolver::ConstantContext.new("::PrivateThing", "private_thing.rb")
45+
46+
ConstantResolver.expects(:new).returns(stub("resolver", resolve: context))
47+
48+
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
49+
validator.package_set,
50+
config
51+
)
52+
53+
refute result.ok?, result.error_value
54+
assert_match(
55+
%r{'::PrivateThing' is declared as private in the 'components/timeline' package},
56+
result.error_value
57+
)
58+
assert_match(
59+
/but appears to be defined\sin the '.' package/,
60+
result.error_value
61+
)
62+
end
63+
64+
test "check_package_manifests_for_privacy returns an error for constants without `::` prefix" do
65+
use_template(:minimal)
66+
merge_into_app_yaml_file("package.yml", { "enforce_privacy" => ["::PrivateThing", "OtherThing"] })
67+
68+
result = Packwerk::ApplicationValidator::CheckPackageManifestsForPrivacy.call(
69+
validator.package_set,
70+
config
71+
)
72+
73+
refute result.ok?, result.error_value
74+
assert_match(
75+
/'OtherThing', listed in the 'enforce_privacy' option in .*package.yml, is invalid./,
76+
result.error_value
77+
)
78+
assert_match(
79+
/Private constants need to be prefixed with the top-level namespace operator `::`/,
80+
result.error_value
81+
)
82+
end
83+
84+
sig { returns(Packwerk::ApplicationValidator) }
85+
def validator
86+
@application_validator ||= Packwerk::ApplicationValidator.new(
87+
config_file_path: config.config_path,
88+
configuration: config,
89+
environment: "test"
90+
)
91+
end
92+
end
93+
end

0 commit comments

Comments
 (0)