• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang assert.NilError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/docker/docker/pkg/testutil/assert.NilError函数的典型用法代码示例。如果您正苦于以下问题:Golang NilError函数的具体用法?Golang NilError怎么用?Golang NilError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NilError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
}
开发者ID:docker,项目名称:docker,代码行数:7,代码来源:opts_test.go


示例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))
}
开发者ID:hyperledger,项目名称:fabric,代码行数:31,代码来源:metastate_test.go


示例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))
}
开发者ID:Mic92,项目名称:docker,代码行数:7,代码来源:opts_test.go


示例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))
			}
		}
	}
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:58,代码来源:ps_test.go


示例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")
}
开发者ID:CheggEng,项目名称:docker,代码行数:9,代码来源:opts_test.go


示例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")
}
开发者ID:CheggEng,项目名称:docker,代码行数:9,代码来源:opts_test.go


示例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}
}
开发者ID:jfrazelle,项目名称:docker,代码行数:10,代码来源:tempfile.go


示例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")
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:11,代码来源:config_test.go


示例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")
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:15,代码来源:daemon_test.go


示例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)
}
开发者ID:docker,项目名称:docker,代码行数:35,代码来源:volume_test.go


示例11: TestDaemonCommand

func TestDaemonCommand(t *testing.T) {
	cmd := newDaemonCommand()
	cmd.RunE = stubRun
	cmd.SetArgs([]string{"--containerd", "/foo"})
	err := cmd.Execute()
	assert.NilError(t, err)
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:7,代码来源:daemon_unit_test.go


示例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")
}
开发者ID:docker,项目名称:docker,代码行数:7,代码来源:quotedstring_test.go


示例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)
}
开发者ID:justincormack,项目名称:docker,代码行数:26,代码来源:service_test.go


示例14: TestDaemonCommandHelp

func TestDaemonCommandHelp(t *testing.T) {
	cmd := newDaemonCommand()
	cmd.RunE = stubRun
	cmd.SetArgs([]string{"--help"})
	err := cmd.Execute()
	assert.NilError(t, err)
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:7,代码来源:daemon_unit_test.go


示例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.")
}
开发者ID:docker,项目名称:docker,代码行数:7,代码来源:leave_test.go


示例16: TestExternalCAOption

func TestExternalCAOption(t *testing.T) {
	testCases := []struct {
		externalCA string
		expected   string
	}{
		{
			externalCA: "protocol=cfssl,url=anything",
			expected:   "cfssl: anything",
		},
		{
			externalCA: "protocol=CFSSL,url=anything",
			expected:   "cfssl: anything",
		},
		{
			externalCA: "protocol=Cfssl,url=https://example.com",
			expected:   "cfssl: https://example.com",
		},
		{
			externalCA: "protocol=Cfssl,url=https://example.com,foo=bar",
			expected:   "cfssl: https://example.com",
		},
		{
			externalCA: "protocol=Cfssl,url=https://example.com,foo=bar,foo=baz",
			expected:   "cfssl: https://example.com",
		},
	}
	for _, tc := range testCases {
		opt := &ExternalCAOption{}
		assert.NilError(t, opt.Set(tc.externalCA))
		assert.Equal(t, opt.String(), tc.expected)
	}
}
开发者ID:docker,项目名称:docker,代码行数:32,代码来源:opts_test.go


示例17: TestMountOptDefaultEnableReadOnly

func TestMountOptDefaultEnableReadOnly(t *testing.T) {
	var m MountOpt
	assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo"))
	assert.Equal(t, m.values[0].ReadOnly, false)

	m = MountOpt{}
	assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
	assert.Equal(t, m.values[0].ReadOnly, true)

	m = MountOpt{}
	assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
	assert.Equal(t, m.values[0].ReadOnly, true)

	m = MountOpt{}
	assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
	assert.Equal(t, m.values[0].ReadOnly, false)
}
开发者ID:maxim28,项目名称:docker,代码行数:17,代码来源:opts_test.go


示例18: TestConvertRestartPolicyFromAlways

func TestConvertRestartPolicyFromAlways(t *testing.T) {
	policy, err := convertRestartPolicy("always", nil)
	expected := &swarm.RestartPolicy{
		Condition: swarm.RestartPolicyConditionAny,
	}
	assert.NilError(t, err)
	assert.DeepEqual(t, policy, expected)
}
开发者ID:justincormack,项目名称:docker,代码行数:8,代码来源:service_test.go


示例19: TestHealthCheckOptionsToHealthConfigNoHealthcheck

func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
	opt := healthCheckOptions{
		noHealthcheck: true,
	}
	config, err := opt.toHealthConfig()
	assert.NilError(t, err)
	assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{
		Test: []string{"NONE"},
	}), true)
}
开发者ID:Mic92,项目名称:docker,代码行数:10,代码来源:opts_test.go


示例20: TestLoadDaemonCliConfigWithTLS

func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
	opts := defaultOptions("")
	opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
	opts.common.TLS = true

	loadedConfig, err := loadDaemonCliConfig(opts)
	assert.NilError(t, err)
	assert.NotNil(t, loadedConfig)
	assert.Equal(t, loadedConfig.CommonTLSOptions.CAFile, "/tmp/ca.pem")
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:10,代码来源:daemon_test.go



注:本文中的github.com/docker/docker/pkg/testutil/assert.NilError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cmd.Command函数代码示例发布时间:2022-05-23
下一篇:
Golang assert.Error函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap