@@ -13,88 +13,108 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
16- package markerscope
16+ package markerscope_test
1717
1818import (
1919 "testing"
2020
2121 "golang.org/x/tools/go/analysis/analysistest"
22+ "sigs.k8s.io/kube-api-linter/pkg/analysis/markerscope"
2223)
2324
24- func TestAnalyzerWarnOnly (t * testing.T ) {
25+ func TestAnalyzerWithDefaultConfig (t * testing.T ) {
2526 testdata := analysistest .TestData ()
26- cfg := & MarkerScopeConfig {
27- Policy : MarkerScopePolicyWarn ,
27+ // Test with nil config - should use all defaults:
28+ // - Policy: Warn
29+ // - AllowDangerousTypes: false
30+ // - OverrideMarkers: empty (use built-in defaults)
31+ // - CustomMarkers: empty
32+ analyzer , err := markerscope .Initializer ().Init (& markerscope.MarkerScopeConfig {})
33+ if err != nil {
34+ t .Fatal (err )
2835 }
29- analyzer := newAnalyzer (cfg )
3036 analysistest .Run (t , testdata , analyzer , "a" )
3137}
3238
3339func TestAnalyzerSuggestFixes (t * testing.T ) {
3440 testdata := analysistest .TestData ()
35- cfg := & MarkerScopeConfig {
36- Policy : MarkerScopePolicySuggestFix ,
41+ cfg := & markerscope.MarkerScopeConfig {
42+ Policy : markerscope .MarkerScopePolicySuggestFix ,
43+ }
44+ analyzer , err := markerscope .Initializer ().Init (cfg )
45+ if err != nil {
46+ t .Fatal (err )
3747 }
38- analyzer := newAnalyzer (cfg )
3948 analysistest .RunWithSuggestedFixes (t , testdata , analyzer , "a" )
4049}
4150
4251func TestAnalyzerWithCustomAndOverrideMarkers (t * testing.T ) {
4352 testdata := analysistest .TestData ()
44- cfg := & MarkerScopeConfig {
45- Policy : MarkerScopePolicyWarn ,
46- OverrideMarkers : []MarkerScopeRule {
53+ cfg := & markerscope. MarkerScopeConfig {
54+ Policy : markerscope . MarkerScopePolicyWarn ,
55+ OverrideMarkers : []markerscope. MarkerScopeRule {
4756 // Override built-in "optional" to allow on types (default is FieldScope only)
4857 {
4958 Identifier : "optional" ,
50- Scope : AnyScope ,
59+ Scope : markerscope . AnyScope ,
5160 },
5261 // Override built-in "required" to allow on types (default is FieldScope only)
5362 {
5463 Identifier : "required" ,
55- Scope : AnyScope ,
64+ Scope : markerscope . AnyScope ,
5665 },
5766 },
58- CustomMarkers : []MarkerScopeRule {
67+ CustomMarkers : []markerscope. MarkerScopeRule {
5968 // Custom field-only marker
6069 {
6170 Identifier : "custom:field-only" ,
62- Scope : FieldScope ,
71+ Scope : markerscope . FieldScope ,
6372 },
6473 // Custom type-only marker
6574 {
6675 Identifier : "custom:type-only" ,
67- Scope : TypeScope ,
76+ Scope : markerscope . TypeScope ,
6877 },
6978 // Custom marker with string type constraint
7079 {
7180 Identifier : "custom:string-only" ,
72- Scope : FieldScope ,
73- TypeConstraint : & TypeConstraint {
74- AllowedSchemaTypes : []SchemaType {SchemaTypeString },
81+ Scope : markerscope .FieldScope ,
82+ TypeConstraint : & markerscope.TypeConstraint {
83+ AllowedSchemaTypes : []markerscope.SchemaType {
84+ markerscope .SchemaTypeString ,
85+ },
7586 },
7687 },
7788 // Custom marker with integer type constraint
7889 {
7990 Identifier : "custom:integer-only" ,
80- Scope : FieldScope ,
81- TypeConstraint : & TypeConstraint {
82- AllowedSchemaTypes : []SchemaType {SchemaTypeInteger },
91+ Scope : markerscope .FieldScope ,
92+ TypeConstraint : & markerscope.TypeConstraint {
93+ AllowedSchemaTypes : []markerscope.SchemaType {
94+ markerscope .SchemaTypeInteger ,
95+ },
8396 },
8497 },
8598 // Custom marker with array of strings constraint
8699 {
87100 Identifier : "custom:string-array" ,
88- Scope : FieldScope ,
89- TypeConstraint : & TypeConstraint {
90- AllowedSchemaTypes : []SchemaType {SchemaTypeArray },
91- ElementConstraint : & TypeConstraint {
92- AllowedSchemaTypes : []SchemaType {SchemaTypeString },
101+ Scope : markerscope .FieldScope ,
102+ TypeConstraint : & markerscope.TypeConstraint {
103+ AllowedSchemaTypes : []markerscope.SchemaType {
104+ markerscope .SchemaTypeArray ,
105+ },
106+ ElementConstraint : & markerscope.TypeConstraint {
107+ AllowedSchemaTypes : []markerscope.SchemaType {
108+ markerscope .SchemaTypeString ,
109+ },
93110 },
94111 },
95112 },
96113 },
97114 }
98- analyzer := newAnalyzer (cfg )
115+ analyzer , err := markerscope .Initializer ().Init (cfg )
116+ if err != nil {
117+ t .Fatal (err )
118+ }
99119 analysistest .Run (t , testdata , analyzer , "b" )
100120}
0 commit comments