mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #65326 from deads2k/cli-75-fix-printer-check
Automatic merge from submit-queue (batch tested with PRs 65290, 65326, 65289, 65334, 64860). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fix printer check to tolerate vendoring After you've vendored code, the package includes a vendor dir. This updates the code to tolerate that. /assign @soltysh @juanvallejo ```release-note NONE ```
This commit is contained in:
commit
3a7c3d387c
@ -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