Fix unit tests and comments
Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
4b6d0c0738
commit
1d8e7f4695
7 changed files with 17 additions and 40 deletions
|
@ -18,6 +18,7 @@ package certs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
@ -47,7 +48,8 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
|||
|
||||
cmd.Flags().String("host", "", "Get the cert for this hostname")
|
||||
if err := cobra.MarkFlagRequired(cmd.Flags(), "host"); err != nil {
|
||||
fmt.Printf("error marking flag as required: %v", err)
|
||||
util.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pod = util.AddPodFlag(cmd)
|
||||
deployment = util.AddDeploymentFlag(cmd)
|
||||
|
|
|
@ -78,9 +78,7 @@ func execToWriter(args []string, writer io.Writer) error {
|
|||
}
|
||||
|
||||
go func() {
|
||||
if _, err := io.Copy(writer, op); err != nil {
|
||||
fmt.Printf("Error copying output: %v\n", err)
|
||||
}
|
||||
io.Copy(writer, op) //nolint:errcheck
|
||||
}()
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
|
|
|
@ -103,9 +103,7 @@ func TestNginxCheck(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
go func() {
|
||||
if err := cmd.Wait(); err != nil {
|
||||
t.Errorf("unexpected error waiting for the process: %v", err)
|
||||
}
|
||||
cmd.Wait() //nolint:errcheck
|
||||
}()
|
||||
|
||||
if _, err := pidFile.Write([]byte(fmt.Sprintf("%v", pid))); err != nil {
|
||||
|
@ -123,9 +121,7 @@ func TestNginxCheck(t *testing.T) {
|
|||
})
|
||||
|
||||
// pollute pid file
|
||||
if _, err := pidFile.Write([]byte("999999")); err != nil {
|
||||
t.Errorf("unexpected error polluting the pid file: %v", err)
|
||||
}
|
||||
pidFile.Write([]byte("999999")) //nolint:errcheck
|
||||
pidFile.Close()
|
||||
|
||||
t.Run("bad pid", func(t *testing.T) {
|
||||
|
|
|
@ -92,11 +92,7 @@ func TestStore(t *testing.T) {
|
|||
|
||||
emptySelector, _ := labels.Parse("")
|
||||
|
||||
defer func() {
|
||||
if err := te.Stop(); err != nil {
|
||||
t.Errorf("error: %v", err)
|
||||
}
|
||||
}()
|
||||
defer te.Stop() //nolint:errcheck
|
||||
|
||||
clientSet, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,13 +18,14 @@ package template
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha1" // #nosec
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand" // #nosec
|
||||
"math/big"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -34,7 +35,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
text_template "text/template"
|
||||
"time"
|
||||
|
||||
networkingv1 "k8s.io/api/networking/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
@ -1186,16 +1186,16 @@ func buildAuthSignURLLocation(location, authSignURL string) string {
|
|||
}
|
||||
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
var random *rand.Rand
|
||||
|
||||
func init() {
|
||||
random = rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec
|
||||
}
|
||||
|
||||
func randomString() string {
|
||||
b := make([]rune, 32)
|
||||
for i := range b {
|
||||
b[i] = letters[random.Intn(len(letters))] // #nosec
|
||||
idx, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
|
||||
if err != nil {
|
||||
klog.Errorf("unexpected error generating random index: %v", err)
|
||||
return ""
|
||||
}
|
||||
b[i] = letters[idx.Int64()]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
|
|
|
@ -48,10 +48,7 @@ func TestProcessCollector(t *testing.T) {
|
|||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error waiting for dummy process: %v", err)
|
||||
}
|
||||
cmd.Wait() //nolint:errcheck
|
||||
status := cmd.ProcessState.Sys().(syscall.WaitStatus)
|
||||
if status.Signaled() {
|
||||
t.Logf("Signal: %v", status.Signal())
|
||||
|
@ -72,11 +69,8 @@ func TestProcessCollector(t *testing.T) {
|
|||
defer func() {
|
||||
cm.Stop()
|
||||
|
||||
err = cmd.Process.Kill()
|
||||
cmd.Process.Kill() //nolint:errcheck
|
||||
<-done
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error killing dummy process: %v", err)
|
||||
}
|
||||
close(done)
|
||||
}()
|
||||
|
||||
|
|
|
@ -228,20 +228,11 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
|||
flags.IntVar(&nginx.MaxmindRetriesCount, "maxmind-retries-count", 1, "Number of attempts to download the GeoIP DB.")
|
||||
flags.DurationVar(&nginx.MaxmindRetriesTimeout, "maxmind-retries-timeout", time.Second*0, "Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong.")
|
||||
|
||||
if err := flag.Set("logtostderr", "true"); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
flags.AddGoFlagSet(flag.CommandLine)
|
||||
if err := flags.Parse(os.Args); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
// Workaround for this issue:
|
||||
// https://github.com/kubernetes/kubernetes/issues/17162
|
||||
if err := flag.CommandLine.Parse([]string{}); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
pflag.VisitAll(func(flag *pflag.Flag) {
|
||||
klog.V(2).InfoS("FLAG", flag.Name, flag.Value)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue