mirror of https://github.com/k3s-io/k3s
fix printer check to tolerate vendoring
parent
23b4690d00
commit
6dd9d1fff7
|
@ -83,6 +83,7 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
printFlags := genericclioptions.NewPrintFlags("succeeded").WithTypeSetter(scheme.Scheme)
|
||||
printFlags.OutputFormat = &tc.output
|
||||
|
||||
|
@ -102,7 +103,7 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||
if !genericprinters.IsInternalObjectError(err) {
|
||||
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if tc.expectInternalObjErr {
|
||||
|
@ -110,12 +111,13 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||
}
|
||||
|
||||
if len(tc.expectedOutput) == 0 {
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if 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 {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
output := bytes.NewBuffer([]byte{})
|
||||
|
||||
err := tc.printer.PrintObj(tc.obj, output)
|
||||
|
@ -192,7 +195,7 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||
if !genericprinters.IsInternalObjectError(err) {
|
||||
t.Fatalf("unexpected error - expecting internal object printer error, got %q", err)
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if tc.expectInternalObjErr {
|
||||
|
@ -200,12 +203,13 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||
}
|
||||
|
||||
if len(tc.expectedOutput) == 0 {
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if 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 {
|
||||
for _, forbiddenPrefix := range c.disallowedPrefixes {
|
||||
if strings.HasPrefix(pkgPath, forbiddenPrefix) {
|
||||
if strings.HasPrefix(pkgPath, forbiddenPrefix) || strings.Contains(pkgPath, "/vendor/"+forbiddenPrefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue