mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
kubeadm: fix flaky test TestRunRenewCommands
Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
parent
3be9a8cc73
commit
97db0caf6b
@ -23,6 +23,7 @@ import (
|
|||||||
"crypto"
|
"crypto"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -269,7 +270,7 @@ func TestRunRenewCommands(t *testing.T) {
|
|||||||
if len(test.Args) > 0 {
|
if len(test.Args) > 0 {
|
||||||
args = test.Args + " " + args
|
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
|
// certs renew doesn't support positional Args
|
||||||
if (err != nil) != test.expectedError {
|
if (err != nil) != test.expectedError {
|
||||||
t.Errorf("failed to run renew commands, expected error: %t, actual error: %v", test.expectedError, err)
|
t.Errorf("failed to run renew commands, expected error: %t, actual error: %v", test.expectedError, err)
|
||||||
|
@ -18,6 +18,7 @@ package kubeadm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"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
|
// 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 := getSubCommand(t, subCmds, command)
|
||||||
|
subCmd.SetOut(output)
|
||||||
subCmd.SetArgs(args)
|
subCmd.SetArgs(args)
|
||||||
if err := subCmd.Execute(); err != nil {
|
if err := subCmd.Execute(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user