Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jun 28, 2024
1 parent 7b09059 commit a0cf8c2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
19 changes: 14 additions & 5 deletions cmd/containerd-shim-runhcs-v1/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"sync"
"testing"
"time"

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime/v2/task"
Expand Down Expand Up @@ -96,8 +97,10 @@ func setupTestPodWithFakes(t *testing.T) (*pod, *testShimTask) {
execs: make(map[string]*testShimExec),
}
// Add a 2nd exec
seid := strconv.Itoa(rand.Int())
st.execs[seid] = newTestShimExec(t.Name(), seid, int(rand.Int31()))
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))
seid := strconv.FormatInt((int64)(source.Uint64()), 10)
st.execs[seid] = newTestShimExec(t.Name(), seid, int(source.Uint64()))
p := &pod{
id: t.Name(),
sandboxTask: st,
Expand All @@ -107,10 +110,13 @@ func setupTestPodWithFakes(t *testing.T) (*pod, *testShimTask) {

func setupTestTaskInPod(t *testing.T, p *pod) *testShimTask {
t.Helper()
tid := strconv.Itoa(rand.Int())
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))
tid := strconv.FormatInt((int64)(source.Uint64()), 10)

wt := &testShimTask{
id: tid,
exec: newTestShimExec(tid, tid, int(rand.Int31())),
exec: newTestShimExec(tid, tid, int(source.Uint64())),
}
p.workloadTasks.Store(wt.id, wt)
return wt
Expand Down Expand Up @@ -385,6 +391,9 @@ func Test_pod_DeleteTask_TaskID_Not_Created(t *testing.T) {
setupTestTaskInPod(t, p)
setupTestTaskInPod(t, p)

err := p.KillTask(context.Background(), strconv.Itoa(rand.Int()), "", 0xf, true)
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))

err := p.KillTask(context.Background(), strconv.Itoa((int)(source.Uint64())), "", 0xf, true)
verifyExpectedError(t, nil, err, errdefs.ErrNotFound)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (

func setupPodServiceWithFakes(t *testing.T) (*service, *testShimTask, *testShimTask, *testShimExec) {
t.Helper()
tid := strconv.Itoa(rand.Int())
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))
tid := strconv.FormatInt((int64)(source.Uint64()), 10)

s, err := NewService(WithTID(tid), WithIsSandbox(true))
if err != nil {
Expand All @@ -47,8 +49,9 @@ func setupPodServiceWithFakes(t *testing.T) (*service, *testShimTask, *testShimT
}

// create a 2nd fake container
secondTaskID := strconv.Itoa(rand.Int())
secondTaskSecondExecID := strconv.Itoa(rand.Int())
secondTaskID := strconv.FormatInt((int64)(source.Uint64()), 10)
secondTaskSecondExecID := strconv.FormatInt((int64)(source.Uint64()), 10)

task2 := &testShimTask{
id: secondTaskID,
exec: newTestShimExec(secondTaskID, secondTaskID, 101),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (

func setupTaskServiceWithFakes(t *testing.T) (*service, *testShimTask, *testShimExec) {
t.Helper()
tid := strconv.Itoa(rand.Int())
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))
tid := strconv.FormatInt((int64)(source.Uint64()), 10)

s, err := NewService(WithTID(tid), WithIsSandbox(false))
if err != nil {
Expand All @@ -46,7 +48,7 @@ func setupTaskServiceWithFakes(t *testing.T) (*service, *testShimTask, *testShim
exec: newTestShimExec(tid, tid, 10),
execs: make(map[string]*testShimExec),
}
secondExecID := strconv.Itoa(rand.Int())
secondExecID := strconv.FormatInt((int64)(source.Uint64()), 10)
secondExec := newTestShimExec(tid, secondExecID, 101)
task.execs[secondExecID] = secondExec
s.taskOrPod.Store(task)
Expand Down
9 changes: 6 additions & 3 deletions cmd/containerd-shim-runhcs-v1/task_hcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import (

func setupTestHcsTask(t *testing.T) (*hcsTask, *testShimExec, *testShimExec) {
t.Helper()
initExec := newTestShimExec(t.Name(), t.Name(), int(rand.Int31()))
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))

initExec := newTestShimExec(t.Name(), t.Name(), int(source.Uint64()))
lt := &hcsTask{
events: newFakePublisher(),
id: t.Name(),
init: initExec,
closed: make(chan struct{}),
}
secondExecID := strconv.Itoa(rand.Int())
secondExec := newTestShimExec(t.Name(), secondExecID, int(rand.Int31()))
secondExecID := strconv.FormatInt((int64)(source.Uint64()), 10)
secondExec := newTestShimExec(t.Name(), secondExecID, int(source.Int31()))
lt.execs.Store(secondExecID, secondExec)
return lt, initExec, secondExec
}
Expand Down
2 changes: 1 addition & 1 deletion ext4/dmverity/dmverity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package dmverity

import (
"bytes"
"crypto/rand"
"encoding/binary"
"io"
"math/rand"
"os"
"strings"
"testing"
Expand Down
10 changes: 8 additions & 2 deletions internal/tools/networkagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"context"

"flag"
"fmt"
"math/rand"
Expand All @@ -13,6 +14,9 @@ import (
"strconv"
"strings"
"syscall"
"time"

cryptorand "crypto/rand"

"github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/hcn"
Expand All @@ -37,7 +41,7 @@ const (
func generateMAC() (string, error) {
buf := make([]byte, 6)

_, err := rand.Read(buf)
_, err := cryptorand.Read(buf)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -65,7 +69,9 @@ func generateIPs(prefixLength string) (string, string, string) {
ipGatewayString := ipGateway.String()

// set last byte for IP address in range
last := byte(rand.Intn(255-2) + 2)
seed := time.Now().UnixNano()
source := rand.New(rand.NewSource(seed))
last := byte(source.Uint64())
ipBytes := append(buf, last)
ip := net.IP(ipBytes)
ipString := ip.String()
Expand Down

0 comments on commit a0cf8c2

Please sign in to comment.