File: command_builder_test.go

package info (click to toggle)
golang-github-containerd-nydus-snapshotter 0.13.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,824 kB
  • sloc: sh: 470; makefile: 129
file content (56 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2022. Nydus Developers. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package command

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestBuildCommand(t *testing.T) {

	c := []Opt{WithMode("singleton"),
		WithFscacheDriver("fs_cache_dir"),
		WithFscacheThreads(4),
		WithAPISock("/dummy/apisock"),
		WithUpgrade()}

	args, err := BuildCommand(c)
	assert.Nil(t, err)
	actual := strings.Join(args, " ")
	assert.Equal(t, "singleton --fscache fs_cache_dir --fscache-threads 4 --upgrade --apisock /dummy/apisock", actual)

	c1 := []Opt{WithMode("singleton"),
		WithFscacheDriver("fs_cache_dir"),
		WithFscacheThreads(4),
		WithAPISock("/dummy/apisock")}

	args1, err := BuildCommand(c1)
	assert.Nil(t, err)
	actual1 := strings.Join(args1, " ")
	assert.Equal(t, "singleton --fscache fs_cache_dir --fscache-threads 4 --apisock /dummy/apisock", actual1)
}

// cpu: Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz
// BenchmarkBuildCommand-8   	  394146	      3084 ns/op
// BenchmarkXxx-8            	 3933902	       281.4 ns/op
// PASS
func BenchmarkBuildCommand(b *testing.B) {

	c := []Opt{WithMode("singleton"),
		WithFscacheDriver("fs_cache_dir"),
		WithFscacheThreads(4),
		WithAPISock("/dummy/apisock"),
		WithUpgrade()}

	for n := 0; n < b.N; n++ {
		_, err := BuildCommand(c)
		assert.Nil(b, err)
	}
}