You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pass.Reportf(field.Pos(), "field %s.%s with marker +%s is missing required marker(s): %s", structName, fieldName, rule.Identifier, strings.Join(missing, ", "))
102
103
}
103
104
}
104
105
@@ -118,6 +119,7 @@ func handleAny(pass *analysis.Pass, field *ast.Field, rule Rule, fieldMarkers ma
118
119
dependents[i] =fmt.Sprintf("+%s", d)
119
120
}
120
121
121
-
pass.Reportf(field.Pos(), "field with marker +%s requires at least one of the following markers, but none were found: %s", rule.Identifier, strings.Join(dependents, ", "))
pass.Reportf(field.Pos(), "field %s.%s with marker +%s requires at least one of the following markers, but none were found: %s", structName, fieldName, rule.Identifier, strings.Join(dependents, ", "))
errs=append(errs, field.Required(rulesPath.Index(i).Child("type"), "type must be explicitly set to 'all' or 'any'"))
78
+
errs=append(errs, field.Required(rulesPath.Index(i).Child("type"), fmt.Sprintf("type must be explicitly set to '%s' or '%s'", DependencyTypeAll, DependencyTypeAny)))
77
79
} else {
78
80
switchrule.Type {
79
81
caseDependencyTypeAll, DependencyTypeAny:
80
82
// valid
81
83
default:
82
-
errs=append(errs, field.Invalid(rulesPath.Index(i).Child("type"), rule.Type, "type must be 'all' or 'any'"))
84
+
errs=append(errs, field.Invalid(rulesPath.Index(i).Child("type"), rule.Type, fmt.Sprintf("type must be '%s' or '%s'", DependencyTypeAll, DependencyTypeAny)))
Expect(errs).To(HaveLen(0), "No errors were expected")
43
+
}
44
+
},
45
+
Entry("with a valid config", testCase{
46
+
config: dependenttags.Config{
47
+
Rules: []dependenttags.Rule{
48
+
{
49
+
Identifier: "k8s:unionMember",
50
+
Type: dependenttags.DependencyTypeAll,
51
+
Dependents: []string{"k8s:optional"},
52
+
},
40
53
},
41
54
},
42
-
},
43
-
expectErr: false,
44
-
},
45
-
{
46
-
name: "missing type",
47
-
cfg: &dependenttags.Config{
48
-
Rules: []dependenttags.Rule{
49
-
{
50
-
Identifier: "k8s:unionMember",
51
-
Dependents: []string{"k8s:optional"},
55
+
expectedErr: "",
56
+
}),
57
+
Entry("with missing type", testCase{
58
+
config: dependenttags.Config{
59
+
Rules: []dependenttags.Rule{
60
+
{
61
+
Identifier: "k8s:unionMember",
62
+
Dependents: []string{"k8s:optional"},
63
+
},
52
64
},
53
65
},
54
-
},
55
-
expectErr: true,
56
-
},
57
-
{
58
-
name: "empty rules",
59
-
cfg: &dependenttags.Config{
60
-
Rules: []dependenttags.Rule{},
61
-
},
62
-
expectErr: true,
63
-
},
64
-
{
65
-
name: "missing identifier",
66
-
cfg: &dependenttags.Config{
67
-
Rules: []dependenttags.Rule{
68
-
{
69
-
Type: dependenttags.DependencyTypeAll,
70
-
Dependents: []string{"k8s:optional"},
66
+
expectedErr: fmt.Sprintf("dependenttags.rules[0].type: Required value: type must be explicitly set to '%s' or '%s'", dependenttags.DependencyTypeAll, dependenttags.DependencyTypeAny),
67
+
}),
68
+
Entry("with empty rules", testCase{
69
+
config: dependenttags.Config{
70
+
Rules: []dependenttags.Rule{},
71
+
},
72
+
expectedErr: "dependenttags.rules: Invalid value: []dependenttags.Rule{}: rules cannot be empty",
73
+
}),
74
+
Entry("with missing identifier", testCase{
75
+
config: dependenttags.Config{
76
+
Rules: []dependenttags.Rule{
77
+
{
78
+
Type: dependenttags.DependencyTypeAll,
79
+
Dependents: []string{"k8s:optional"},
80
+
},
71
81
},
72
82
},
73
-
},
74
-
expectErr: true,
75
-
},
76
-
{
77
-
name: "missing dependents",
78
-
cfg: &dependenttags.Config{
79
-
Rules: []dependenttags.Rule{
80
-
{
81
-
Identifier: "k8s:unionMember",
82
-
Type: dependenttags.DependencyTypeAll,
83
+
expectedErr: "dependenttags.rules[0].identifier: Invalid value: \"\": identifier marker cannot be empty",
84
+
}),
85
+
Entry("with missing dependents", testCase{
86
+
config: dependenttags.Config{
87
+
Rules: []dependenttags.Rule{
88
+
{
89
+
Identifier: "k8s:unionMember",
90
+
Type: dependenttags.DependencyTypeAll,
91
+
},
83
92
},
84
93
},
85
-
},
86
-
expectErr: true,
87
-
},
88
-
{
89
-
name: "invalid type",
90
-
cfg: &dependenttags.Config{
91
-
Rules: []dependenttags.Rule{
92
-
{
93
-
Identifier: "k8s:unionMember",
94
-
Type: "invalid",
95
-
Dependents: []string{"k8s:optional"},
94
+
expectedErr: "dependenttags.rules[0].dependents: Invalid value: []string(nil): dependents list cannot be empty",
expectedErr: fmt.Sprintf(`dependenttags.rules[0].type: Invalid value: "invalid": type must be '%s' or '%s'`, dependenttags.DependencyTypeAll, dependenttags.DependencyTypeAny),
Copy file name to clipboardExpand all lines: pkg/analysis/dependenttags/testdata/src/a/a.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ package a
18
18
19
19
typeUnionstruct {
20
20
// +k8s:unionMember
21
-
InvalidMemberstring// want "field with marker \\+k8s:unionMember is missing required marker\\(s\\): \\+k8s:optional"
21
+
InvalidMemberstring// want "field Union.InvalidMember with marker \\+k8s:unionMember is missing required marker\\(s\\): \\+k8s:optional"
22
22
23
23
// +k8s:unionMember
24
24
// +k8s:optional
@@ -27,7 +27,7 @@ type Union struct {
27
27
28
28
typeListstruct {
29
29
// +listType
30
-
InvalidList []string// want "field with marker \\+listType is missing required marker\\(s\\): \\+k8s:listType"
30
+
InvalidList []string// want "field List.InvalidList with marker \\+listType is missing required marker\\(s\\): \\+k8s:listType"
31
31
32
32
// +listType
33
33
// +k8s:listType
@@ -36,7 +36,7 @@ type List struct {
36
36
37
37
typeAnyOfstruct {
38
38
// +example:any
39
-
InvalidAnystring// want "field with marker \\+example:any requires at least one of the following markers, but none were found: \\+dep1, \\+dep2"
39
+
InvalidAnystring// want "field AnyOf.InvalidAny with marker \\+example:any requires at least one of the following markers, but none were found: \\+dep1, \\+dep2"
40
40
41
41
// +example:any
42
42
// +dep1
@@ -52,7 +52,7 @@ type MyString string
52
52
53
53
typeTypeAliasstruct {
54
54
// +example:any
55
-
InvalidAliasstring// want "field with marker \\+example:any requires at least one of the following markers, but none were found: \\+dep1, \\+dep2"
55
+
InvalidAliasstring// want "field TypeAlias.InvalidAlias with marker \\+example:any requires at least one of the following markers, but none were found: \\+dep1, \\+dep2"
0 commit comments