Fix unit tests and comments

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
z1cheng 2023-06-29 14:11:51 +00:00 committed by k8s-infra-cherrypick-robot
parent 4b6d0c0738
commit 1d8e7f4695
7 changed files with 17 additions and 40 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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)

View file

@ -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)
}()