本文整理汇总了Golang中github.com/docker/docker/pkg/testutil/assert.NilError函数的典型用法代码示例。如果您正苦于以下问题:Golang NilError函数的具体用法?Golang NilError怎么用?Golang NilError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NilError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestExternalCAOptionMultiple
func TestExternalCAOptionMultiple(t *testing.T) {
opt := &ExternalCAOption{}
assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com"))
assert.NilError(t, opt.Set("protocol=CFSSL,url=anything"))
assert.Equal(t, len(opt.Value()), 2)
assert.Equal(t, opt.String(), "cfssl: https://example.com, cfssl: anything")
}
示例2: TestNodeMetastate_FromBytes
// Check the deserialization of the meta stats structure
func TestNodeMetastate_FromBytes(t *testing.T) {
metastate := NewNodeMetastate(0)
// Serialize into bytes array
bytes, err := metastate.Bytes()
assert.NilError(t, err)
if bytes == nil {
t.Fatal("Was not able to serialize meta state into byte array.")
}
// Deserialize back and check, that state still have same
// height value
state, err := FromBytes(bytes)
assert.NilError(t, err)
assert.Equal(t, state.Height(), uint64(0))
// Update state to the new height and serialize it again
state.Update(17)
bytes, err = state.Bytes()
assert.NilError(t, err)
if bytes == nil {
t.Fatal("Was not able to serialize meta state into byte array.")
}
// Restore state from byte array and validate
// that stored height is still the same
updatedState, err := FromBytes(bytes)
assert.NilError(t, err)
assert.Equal(t, updatedState.Height(), uint64(17))
}
示例3: TestDurationOptSetAndValue
func TestDurationOptSetAndValue(t *testing.T) {
var duration DurationOpt
assert.NilError(t, duration.Set("300s"))
assert.Equal(t, *duration.Value(), time.Duration(300*10e8))
assert.NilError(t, duration.Set("-300s"))
assert.Equal(t, *duration.Value(), time.Duration(-300*10e8))
}
示例4: TestBuildContainerListOptions
func TestBuildContainerListOptions(t *testing.T) {
filters := opts.NewFilterOpt()
assert.NilError(t, filters.Set("foo=bar"))
assert.NilError(t, filters.Set("baz=foo"))
contexts := []struct {
psOpts *psOptions
expectedAll bool
expectedSize bool
expectedLimit int
expectedFilters map[string]string
}{
{
psOpts: &psOptions{
all: true,
size: true,
last: 5,
filter: filters,
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: map[string]string{
"foo": "bar",
"baz": "foo",
},
},
{
psOpts: &psOptions{
all: true,
size: true,
last: -1,
nLatest: true,
},
expectedAll: true,
expectedSize: true,
expectedLimit: 1,
expectedFilters: make(map[string]string),
},
}
for _, c := range contexts {
options, err := buildContainerListOptions(c.psOpts)
assert.NilError(t, err)
assert.Equal(t, c.expectedAll, options.All)
assert.Equal(t, c.expectedSize, options.Size)
assert.Equal(t, c.expectedLimit, options.Limit)
assert.Equal(t, options.Filter.Len(), len(c.expectedFilters))
for k, v := range c.expectedFilters {
f := options.Filter
if !f.ExactMatch(k, v) {
t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k))
}
}
}
}
示例5: TestAutoAcceptOptionSetConflict
func TestAutoAcceptOptionSetConflict(t *testing.T) {
opt := NewAutoAcceptOption()
assert.NilError(t, opt.Set("manager"))
assert.Error(t, opt.Set("none"), "value NONE is incompatible with MANAGER")
opt = NewAutoAcceptOption()
assert.NilError(t, opt.Set("none"))
assert.Error(t, opt.Set("worker"), "value NONE is incompatible with WORKER")
}
示例6: TestAutoAcceptOptionString
func TestAutoAcceptOptionString(t *testing.T) {
opt := NewAutoAcceptOption()
assert.NilError(t, opt.Set("manager"))
assert.NilError(t, opt.Set("worker"))
repr := opt.String()
assert.Contains(t, repr, "worker=true")
assert.Contains(t, repr, "manager=true")
}
示例7: NewTempFile
// NewTempFile returns a new temp file with contents
func NewTempFile(t assert.TestingT, prefix string, content string) *TempFile {
file, err := ioutil.TempFile("", prefix+"-")
assert.NilError(t, err)
_, err = file.Write([]byte(content))
assert.NilError(t, err)
file.Close()
return &TempFile{File: file}
}
示例8: TestFindConfigurationConflictsWithNamedOptions
func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) {
config := map[string]interface{}{"hosts": []string{"qwer"}}
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
var hosts []string
flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to")
assert.NilError(t, flags.Set("host", "tcp://127.0.0.1:4444"))
assert.NilError(t, flags.Set("host", "unix:///var/run/docker.sock"))
assert.Error(t, findConfigurationConflicts(config, flags), "hosts")
}
示例9: TestLoadDaemonCliConfigWithConflicts
func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
tempFile := tempfile.NewTempFile(t, "config", `{"labels": ["l3=foo"]}`)
defer tempFile.Remove()
configFile := tempFile.Name()
opts := defaultOptions(configFile)
flags := opts.flags
assert.NilError(t, flags.Set(flagDaemonConfigFile, configFile))
assert.NilError(t, flags.Set("label", "l1=bar"))
assert.NilError(t, flags.Set("label", "l2=baz"))
_, err := loadDaemonCliConfig(opts)
assert.Error(t, err, "as a flag and in the configuration file: labels")
}
示例10: TestConvertVolumeToMountNamedVolume
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
stackVolumes := volumes{
"normal": composetypes.VolumeConfig{
Driver: "glusterfs",
DriverOpts: map[string]string{
"opt": "value",
},
Labels: map[string]string{
"something": "labeled",
},
},
}
namespace := NewNamespace("foo")
expected := mount.Mount{
Type: mount.TypeVolume,
Source: "foo_normal",
Target: "/foo",
ReadOnly: true,
VolumeOptions: &mount.VolumeOptions{
Labels: map[string]string{
LabelNamespace: "foo",
"something": "labeled",
},
DriverConfig: &mount.Driver{
Name: "glusterfs",
Options: map[string]string{
"opt": "value",
},
},
},
}
mount, err := convertVolumeToMount("normal:/foo:ro", stackVolumes, namespace)
assert.NilError(t, err)
assert.DeepEqual(t, mount, expected)
}
示例11: TestDaemonCommand
func TestDaemonCommand(t *testing.T) {
cmd := newDaemonCommand()
cmd.RunE = stubRun
cmd.SetArgs([]string{"--containerd", "/foo"})
err := cmd.Execute()
assert.NilError(t, err)
}
示例12: TestQuotedStringSetWithQuotes
func TestQuotedStringSetWithQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
assert.NilError(t, qs.Set("\"something\""))
assert.Equal(t, qs.String(), "something")
assert.Equal(t, value, "something")
}
示例13: TestConvertResourcesFull
func TestConvertResourcesFull(t *testing.T) {
source := composetypes.Resources{
Limits: &composetypes.Resource{
NanoCPUs: "0.003",
MemoryBytes: composetypes.UnitBytes(300000000),
},
Reservations: &composetypes.Resource{
NanoCPUs: "0.002",
MemoryBytes: composetypes.UnitBytes(200000000),
},
}
resources, err := convertResources(source)
assert.NilError(t, err)
expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{
NanoCPUs: 3000000,
MemoryBytes: 300000000,
},
Reservations: &swarm.Resources{
NanoCPUs: 2000000,
MemoryBytes: 200000000,
},
}
assert.DeepEqual(t, resources, expected)
}
示例14: TestDaemonCommandHelp
func TestDaemonCommandHelp(t *testing.T) {
cmd := newDaemonCommand()
cmd.RunE = stubRun
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NilError(t, err)
}
示例15: TestSwarmLeave
func TestSwarmLeave(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newLeaveCommand(
test.NewFakeCli(&fakeClient{}, buf))
assert.NilError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), "Node left the swarm.")
}