Skip to content

Commit

Permalink
smoke: use golangci-lint to improve code quality
Browse files Browse the repository at this point in the history
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Dec 14, 2023
1 parent 743b31f commit fca1671
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions smoke/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PROXY := GOPROXY=${GOPROXY}
endif

build:
golangci-lint run
go test -o smoke.test -c -race -v ./tests

# WORK_DIR=/tmp \
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

"github.com/containerd/containerd/log"
"github.com/containerd/log"
"github.com/containerd/nydus-snapshotter/pkg/converter"
"github.com/stretchr/testify/require"

Expand Down
11 changes: 5 additions & 6 deletions smoke/tests/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// Environment Requirement: Containerd, nerdctl >= 0.22, nydus-snapshotter, nydusd, nydus-image and nydusify.
// Prepare: setup nydus for containerd, reference: /~https://github.com/dragonflyoss/nydus/blob/master/docs/containerd-env-setup.md.
// TestBenchmark will dump json file(benchmark.json) which inlcudes container e2e time, image size, read-amount and read-cout.
// TestBenchmark will dump json file(benchmark.json) which includes container e2e time, image size, read-amount and read-cout.
// Example:
// {
// e2e_time: 2747131
Expand Down Expand Up @@ -68,7 +68,7 @@ func (b *BenchmarkTestSuite) TestBenchmark(t *testing.T) {
b.t.Fatalf("Benchmark don't support image " + image)
}
}
targetImageSize, conversionElapsed := b.prepareImage(b.t, ctx, mode, image)
targetImageSize, conversionElapsed := b.prepareImage(b.t, ctx, image)

// run contaienr
b.testContainerName = uuid.NewString()
Expand All @@ -86,7 +86,7 @@ func (b *BenchmarkTestSuite) TestBenchmark(t *testing.T) {
t.Logf(fmt.Sprintf("Metric: E2ETime %d ConversionElapsed %s ReadCount %d ReadAmount %d ImageSize %d", b.metric.E2ETime, b.metric.ConversionElapsed, b.metric.ReadCount, b.metric.ReadAmountTotal, b.metric.ImageSize))
}

func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, mode string, image string) (int64, int64) {
func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, image string) (int64, int64) {
if b.testImage != "" {
return 0, 0
}
Expand Down Expand Up @@ -129,10 +129,9 @@ func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, mode
if b.snapshotter == "nydus" {
b.testImage = target
return convertMetirc["TargetImageSize"], convertMetirc["ConversionElapsed"]
} else {
b.testImage = source
return convertMetirc["SourceImageSize"], 0
}
b.testImage = source
return convertMetirc["SourceImageSize"], 0
}

func (b *BenchmarkTestSuite) dumpMetric() {
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/blobcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/containerd/containerd/log"
"github.com/containerd/log"
"github.com/dragonflyoss/image-service/smoke/tests/texture"
"github.com/dragonflyoss/image-service/smoke/tests/tool"
"github.com/dragonflyoss/image-service/smoke/tests/tool/test"
Expand Down
6 changes: 3 additions & 3 deletions smoke/tests/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PerformanceTestSuite struct {
testContainerName string
}

func (p *PerformanceTestSuite) TestPerformance(t *testing.T) {
func (p *PerformanceTestSuite) TestPerformance(_ *testing.T) {
ctx := tool.DefaultContext(p.t)
// choose test mode
mode := os.Getenv("PERFORMANCE_TEST_MODE")
Expand Down Expand Up @@ -51,14 +51,14 @@ func (p *PerformanceTestSuite) TestPerformance(t *testing.T) {
}
}
// prepare test image
p.prepareTestImage(p.t, ctx, mode, image)
p.prepareTestImage(p.t, ctx, image)

// run Contaienr
p.testContainerName = uuid.NewString()
tool.RunContainerWithBaseline(p.t, p.testImage, p.testContainerName, mode)
}

func (p *PerformanceTestSuite) prepareTestImage(t *testing.T, ctx *tool.Context, mode string, image string) {
func (p *PerformanceTestSuite) prepareTestImage(t *testing.T, ctx *tool.Context, image string) {
if p.testImage != "" {
return
}
Expand Down
24 changes: 12 additions & 12 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type mountPath struct {
target string
}

var URL_WAIT = map[string]RunArgs{
var urlWait = map[string]RunArgs{
"wordpress": {
WaitURL: "http://localhost:80",
BaselineReadCount: map[string]uint64{
Expand All @@ -64,7 +64,7 @@ var URL_WAIT = map[string]RunArgs{
},
}

var CMD_STDOUT = map[string]RunArgs{
var cmdStdout = map[string]RunArgs{
"golang": {
Mount: mountPath{
source: "tests/texture/golang",
Expand Down Expand Up @@ -93,13 +93,13 @@ var CMD_STDOUT = map[string]RunArgs{

// SupportContainerImage help to check if we support the image or not
func SupportContainerImage(image string) bool {
_, existsInUrlWait := URL_WAIT[image]
_, existsInCmdStdout := CMD_STDOUT[image]
return existsInUrlWait || existsInCmdStdout
_, existsInURLWait := urlWait[image]
_, existsInCmdStdout := cmdStdout[image]
return existsInURLWait || existsInCmdStdout
}

// runUrlWaitContainer run container util geting http response from WaitUrl
func runUrlWaitContainer(t *testing.T, image string, snapshotter string, containerName string, runArgs RunArgs) {
// runURLWaitContainer run container util getting http response from WaitUrl
func runURLWaitContainer(t *testing.T, image string, snapshotter string, containerName string, runArgs RunArgs) {
cmd := fmt.Sprintf("sudo nerdctl --insecure-registry --snapshotter %s run -d --net=host", snapshotter)
if runArgs.Mount.source != "" {
currentDir, err := os.Getwd()
Expand Down Expand Up @@ -137,9 +137,9 @@ func runCmdStdoutContainer(t *testing.T, image string, snapshotter string, conta
// RunContainerWithBaseline and get metrics from api socket.
// Test will fail if performance below baseline.
func RunContainerWithBaseline(t *testing.T, image string, containerName string, mode string) {
args, ok := URL_WAIT[ImageRepo(t, image)]
args, ok := urlWait[ImageRepo(t, image)]
if ok {
runUrlWaitContainer(t, image, "nydus", containerName, args)
runURLWaitContainer(t, image, "nydus", containerName, args)
defer clearContainer(t, image, "nydus", containerName)
} else {
t.Fatalf(fmt.Sprintf("%s is not in URL_WAIT", image))
Expand All @@ -161,11 +161,11 @@ func RunContainer(t *testing.T, image string, snapshotter string, containerName
startTime := time.Now()

// runContainer
args, ok := URL_WAIT[ImageRepo(t, image)]
args, ok := urlWait[ImageRepo(t, image)]
if ok {
runUrlWaitContainer(t, image, snapshotter, containerName, args)
runURLWaitContainer(t, image, snapshotter, containerName, args)
defer clearContainer(t, image, snapshotter, containerName)
} else if args, ok := CMD_STDOUT[ImageRepo(t, image)]; ok {
} else if args, ok := cmdStdout[ImageRepo(t, image)]; ok {
runCmdStdoutContainer(t, image, snapshotter, containerName, args)
defer clearContainer(t, image, snapshotter, containerName)
}
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/tool/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func (ctx *Context) PrepareWorkDir(t *testing.T) {
}
}

func (ctx *Context) Destroy(t *testing.T) {
func (ctx *Context) Destroy(_ *testing.T) {
os.RemoveAll(ctx.Env.WorkDir)
}
5 changes: 2 additions & 3 deletions smoke/tests/tool/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ func (c *DescartesIterator) calNext() {
carried = true
cursors[idx]++
break
} else {
carried = false
cursors[idx] = 0
}
carried = false
cursors[idx] = 0
}
if !carried {
c.noNext()
Expand Down
4 changes: 2 additions & 2 deletions smoke/tests/tool/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (l *Layer) PackRef(t *testing.T, ctx Context, blobDir string, compress bool
return ociBlobDigest, rafsBlobDigest
}

func (l *Layer) Overlay(t *testing.T, upper *Layer) *Layer {
func (l *Layer) Overlay(_ *testing.T, upper *Layer) *Layer {
// Handle whiteout/opaque files
for upperName := range upper.FileTree {
name := filepath.Base(upperName)
Expand Down Expand Up @@ -237,7 +237,7 @@ func (l *Layer) recordFileTree(t *testing.T) {
})
}

func (l *Layer) ToOCITar(t *testing.T) io.ReadCloser {
func (l *Layer) ToOCITar(_ *testing.T) io.ReadCloser {
return archive.Diff(context.Background(), "", l.workDir)
}

Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/tool/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"testing"

"github.com/containerd/containerd/log"
"github.com/containerd/log"
"github.com/stretchr/testify/require"
)

Expand Down

0 comments on commit fca1671

Please sign in to comment.