mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
fix printer check to tolerate vendoring
This commit is contained in:
parent
23b4690d00
commit
6dd9d1fff7
@ -83,6 +83,7 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
printFlags := genericclioptions.NewPrintFlags("succeeded").WithTypeSetter(scheme.Scheme)
|
printFlags := genericclioptions.NewPrintFlags("succeeded").WithTypeSetter(scheme.Scheme)
|
||||||
printFlags.OutputFormat = &tc.output
|
printFlags.OutputFormat = &tc.output
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||||||
if !genericprinters.IsInternalObjectError(err) {
|
if !genericprinters.IsInternalObjectError(err) {
|
||||||
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.expectInternalObjErr {
|
if tc.expectInternalObjErr {
|
||||||
@ -110,12 +111,13 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(tc.expectedOutput) == 0 {
|
if len(tc.expectedOutput) == 0 {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.expectedOutput != output.String() {
|
if tc.expectedOutput != output.String() {
|
||||||
t.Fatalf("unexpected output: expecting %q, got %q", tc.expectedOutput, output.String())
|
t.Fatalf("unexpected output: expecting %q, got %q", tc.expectedOutput, output.String())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +183,7 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
output := bytes.NewBuffer([]byte{})
|
output := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
err := tc.printer.PrintObj(tc.obj, output)
|
err := tc.printer.PrintObj(tc.obj, output)
|
||||||
@ -192,7 +195,7 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||||||
if !genericprinters.IsInternalObjectError(err) {
|
if !genericprinters.IsInternalObjectError(err) {
|
||||||
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.expectInternalObjErr {
|
if tc.expectInternalObjErr {
|
||||||
@ -200,12 +203,13 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(tc.expectedOutput) == 0 {
|
if len(tc.expectedOutput) == 0 {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.expectedOutput != output.String() {
|
if tc.expectedOutput != output.String() {
|
||||||
t.Fatalf("unexpected output: expecting %q, got %q", tc.expectedOutput, output.String())
|
t.Fatalf("unexpected output: expecting %q, got %q", tc.expectedOutput, output.String())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ type illegalPackageSourceChecker struct {
|
|||||||
|
|
||||||
func (c *illegalPackageSourceChecker) IsForbidden(pkgPath string) bool {
|
func (c *illegalPackageSourceChecker) IsForbidden(pkgPath string) bool {
|
||||||
for _, forbiddenPrefix := range c.disallowedPrefixes {
|
for _, forbiddenPrefix := range c.disallowedPrefixes {
|
||||||
if strings.HasPrefix(pkgPath, forbiddenPrefix) {
|
if strings.HasPrefix(pkgPath, forbiddenPrefix) || strings.Contains(pkgPath, "/vendor/"+forbiddenPrefix) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user