kubeadm: fix flaky test TestRunRenewCommands

Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
xin.li 2024-01-01 20:45:53 +08:00
parent 3be9a8cc73
commit 97db0caf6b
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