Fix golang-ci linter errors (#10128)

* Fix golang-ci linter errors

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix gofmt errors

Signed-off-by: z1cheng <imchench@gmail.com>

* Add nolint comment to defaults.Backend in Configuration

Signed-off-by: z1cheng <imchench@gmail.com>

* Add #nosec comment to rand.New func

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix errcheck warnings

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix gofmt check

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix unit tests and comments

Signed-off-by: z1cheng <imchench@gmail.com>

---------

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
Chen Chen 2023-07-03 20:50:52 +08:00 committed by GitHub
parent f50431a9f9
commit d44a8e0045
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 206 additions and 162 deletions

View file

@ -42,9 +42,9 @@ func (f *FakeProcess) exiterFunc(code int) {
f.exitCode = code
}
func sendDelayedSignal(delay time.Duration) {
func sendDelayedSignal(delay time.Duration) error {
time.Sleep(delay * time.Second)
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
return syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
}
func TestHandleSigterm(t *testing.T) {
@ -66,7 +66,12 @@ func TestHandleSigterm(t *testing.T) {
for _, tt := range tests {
process := &FakeProcess{shouldError: tt.shouldError}
t.Run(tt.name, func(t *testing.T) {
go sendDelayedSignal(2) // Send a signal after 2 seconds
go func() {
err := sendDelayedSignal(2) // Send a signal after 2 seconds
if err != nil {
t.Errorf("error sending delayed signal: %v", err)
}
}()
HandleSigterm(process, tt.delay, process.exiterFunc)
})
if tt.shouldError && process.exitCode != 1 {