Merge pull request #122545 from my-git9/cert-fake-fix

kubeadm: fix flaky test TestRunRenewCommands
This commit is contained in:
Kubernetes Prow Robot 2024-01-01 17:42:13 +01:00 committed by GitHub
commit 6cf77098aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import (
"crypto"
"crypto/x509"
"fmt"
"io"
"os"
"path/filepath"
"strings"
@ -269,7 +270,7 @@ func TestRunRenewCommands(t *testing.T) {
if len(test.Args) > 0 {
args = test.Args + " " + args
}
err := cmdtestutil.RunSubCommand(t, renewCmds, test.command, args)
err := cmdtestutil.RunSubCommand(t, renewCmds, test.command, io.Discard, args)
// certs renew doesn't support positional Args
if (err != nil) != test.expectedError {
t.Errorf("failed to run renew commands, expected error: %t, actual error: %v", test.expectedError, err)

View File

@ -18,6 +18,7 @@ package kubeadm
import (
"bytes"
"io"
"os"
"os/exec"
"testing"
@ -50,8 +51,9 @@ func RunCmd(command string, args ...string) (string, string, int, error) {
}
// RunSubCommand is a utility function for kubeadm testing that executes a Cobra sub command
func RunSubCommand(t *testing.T, subCmds []*cobra.Command, command string, args ...string) error {
func RunSubCommand(t *testing.T, subCmds []*cobra.Command, command string, output io.Writer, args ...string) error {
subCmd := getSubCommand(t, subCmds, command)
subCmd.SetOut(output)
subCmd.SetArgs(args)
if err := subCmd.Execute(); err != nil {
return err