当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.NoError函数代码示例

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


在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLiveCommand_Start

func TestLiveCommand_Start(t *testing.T) {
	lc := NewLiveCommand("/bin/ls")
	err := lc.Start("/tmp")
	assert.NoError(t, err)

	assert.Equal(t, []string{"/bin/ls", "/tmp"}, lc.cmd.Args)

	err = lc.Stop()
	assert.NoError(t, err)
}
开发者ID:alexcb,项目名称:doit,代码行数:10,代码来源:commmand_test.go

示例2: TestSSH_ID

func TestSSH_ID(t *testing.T) {
	didFetchDroplet := false

	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			GetFn: func(id int) (*godo.Droplet, *godo.Response, error) {
				assert.Equal(t, id, testDroplet.ID, "droplet ids did not match")
				didFetchDroplet = true
				return &testDroplet, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ms := &sshMock{}
		c.SSHFn = ms.cmd()

		ns := "test"
		err := RunSSH(ns, c, ioutil.Discard, []string{strconv.Itoa(testDroplet.ID)})
		assert.NoError(t, err)
		assert.True(t, didFetchDroplet)
		assert.True(t, ms.didRun)
		assert.Equal(t, "root", ms.user)
		assert.Equal(t, testDroplet.Networks.V4[0].IPAddress, ms.host)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:26,代码来源:ssh_test.go

示例3: TestSSH_Name

func TestSSH_Name(t *testing.T) {
	didFetchDroplet := false

	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			ListFn: func(*godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
				didFetchDroplet = true
				return testDropletList, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ms := &sshMock{}
		c.SSHFn = ms.cmd()

		ns := "test"

		err := RunSSH(ns, c, ioutil.Discard, []string{testDroplet.Name})
		assert.NoError(t, err)

		assert.Equal(t, "root", ms.user)
		assert.Equal(t, testDroplet.Networks.V4[0].IPAddress, ms.host)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:25,代码来源:ssh_test.go

示例4: TestDropletCreate

func TestDropletCreate(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			CreateFn: func(cr *godo.DropletCreateRequest) (*godo.Droplet, *godo.Response, error) {
				expected := &godo.DropletCreateRequest{
					Name:     "droplet",
					Image:    godo.DropletCreateImage{Slug: "image"},
					Region:   "dev0",
					Size:     "1gb",
					UserData: "#cloud-config",
					SSHKeys:  []godo.DropletCreateSSHKey{},
				}

				assert.Equal(t, cr, expected, "create requests did not match")

				return &testDroplet, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRegionSlug, "dev0")
		c.Set(ns, doit.ArgSizeSlug, "1gb")
		c.Set(ns, doit.ArgImage, "image")
		c.Set(ns, doit.ArgUserData, "#cloud-config")

		err := RunDropletCreate(ns, c, ioutil.Discard, []string{"droplet"})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:31,代码来源:droplets_test.go

示例5: TestSSHPublicKeyImportWithName

func TestSSHPublicKeyImportWithName(t *testing.T) {
	pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCn6eZ8ve0ha04rPRZuoPXK1AQ/h21qslWCzoDcOciXn5OcyafkZw+31k/afaBTeW62D8fXd8e/1xWbFfp/2GqmslYpNCTPrtpNhsE8I0yKjJ8FxX9FfsCOu/Sv83dWgSpiT7pNWVKarZjW9KdKKRQljq1i+H5pX3r5Q9I1v+66mYTe7qsKGas9KWy0vkGoNSqmTCl+d+Y0286chtqBqBjSCUCI8oLKPnJB86Lj344tFGmzDIsJKXMVHTL0dF8n3u6iWN4qiRU+JvkoIkI3v0JvyZXxhR2uPIS1yUAY2GC+2O5mfxydJQzBdtag5Uw8Y7H5yYR1gar/h16bAy5XzRvp testkey"
	path := filepath.Join(os.TempDir(), "key.pub")
	err := ioutil.WriteFile(path, []byte(pubkey), 0600)
	assert.NoError(t, err)
	defer os.Remove(path)

	client := &godo.Client{
		Keys: &doit.KeysServiceMock{
			CreateFn: func(req *godo.KeyCreateRequest) (*godo.Key, *godo.Response, error) {
				expected := &godo.KeyCreateRequest{
					Name:      "custom",
					PublicKey: pubkey,
				}
				assert.Equal(t, req, expected)
				return &testKey, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgKeyPublicKeyFile, path)

		RunKeyImport(ns, c, ioutil.Discard, []string{"custom"})
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:27,代码来源:sshkeys_test.go

示例6: TestActionList

func TestActionList(t *testing.T) {
	actionDidList := false

	client := &godo.Client{
		Actions: &doit.ActionsServiceMock{
			ListFn: func(opts *godo.ListOptions) ([]godo.Action, *godo.Response, error) {
				actionDidList = true
				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testActionList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunCmdActionList(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)

		if !actionDidList {
			t.Errorf("Action() did not run")
		}
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:27,代码来源:actions_test.go

示例7: TestDropletNeighbors

func TestDropletNeighbors(t *testing.T) {
	didRun := false
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			NeighborsFn: func(id int) ([]godo.Droplet, *godo.Response, error) {
				didRun = true
				assert.Equal(t, id, 1)

				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testDropletList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgDropletID, testDroplet.ID)

		err := RunDropletNeighbors(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
		assert.True(t, didRun)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:27,代码来源:droplets_test.go

示例8: TestRecordsUpdate

func TestRecordsUpdate(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			EditRecordFn: func(name string, id int, req *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) {
				expected := &godo.DomainRecordEditRequest{
					Type: "A",
					Name: "foo.example.com.",
					Data: "192.168.1.1",
				}

				assert.Equal(t, "example.com", name)
				assert.Equal(t, 1, id)
				assert.Equal(t, expected, req)

				return &testRecord, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRecordID, 1)
		c.Set(ns, doit.ArgRecordType, "A")
		c.Set(ns, doit.ArgRecordName, "foo.example.com.")
		c.Set(ns, doit.ArgRecordData, "192.168.1.1")

		err := RunRecordUpdate(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:30,代码来源:domains_test.go

示例9: TestDropletKernelList

func TestDropletKernelList(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			KernelsFn: func(id int, opts *godo.ListOptions) ([]godo.Kernel, *godo.Response, error) {
				if got, expected := id, 1; got != expected {
					t.Errorf("KernelsFn() id = %d; expected %d", got, expected)
				}

				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testKernelList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgDropletID, testDroplet.ID)

		err := RunDropletKernels(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:26,代码来源:droplets_test.go

示例10: TestActionGet

func TestActionGet(t *testing.T) {
	client := &godo.Client{
		Actions: &doit.ActionsServiceMock{
			GetFn: func(id int) (*godo.Action, *godo.Response, error) {
				if got, expected := id, testAction.ID; got != expected {
					t.Errorf("GetFn() called with %d; expected %d", got, expected)
				}
				return &testAction, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		err := RunCmdActionGet("test", c, ioutil.Discard, []string{strconv.Itoa(testAction.ID)})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:17,代码来源:actions_test.go

示例11: TestDropletGet

func TestDropletGet(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			GetFn: func(id int) (*godo.Droplet, *godo.Response, error) {
				assert.Equal(t, id, testDroplet.ID, "droplet ids did not match")
				return &testDroplet, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"

		err := RunDropletGet(ns, c, ioutil.Discard, []string{strconv.Itoa(testDroplet.ID)})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:17,代码来源:droplets_test.go

示例12: TestDomainsDelete

func TestDomainsDelete(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			DeleteFn: func(name string) (*godo.Response, error) {
				if got, expected := name, testDomain.Name; got != expected {
					t.Errorf("DeleteFn() received %q; expected %q", got, expected)
				}
				return nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunDomainDelete(ns, c, ioutil.Discard, []string{testDomain.Name})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:18,代码来源:domains_test.go

示例13: TestRecordsList

func TestRecordsList(t *testing.T) {
	recordsDidList := false

	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			RecordsFn: func(name string, opts *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) {
				recordsDidList = true
				return testRecordList, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"

		err := RunRecordList(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
		assert.True(t, recordsDidList)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:20,代码来源:domains_test.go

示例14: TestRecordsDelete

func TestRecordsDelete(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			DeleteRecordFn: func(name string, id int) (*godo.Response, error) {
				if got, expected := name, "example.com"; got != expected {
					t.Errorf("CreateFn domain name = %q; expected %q", got, expected)
				}
				if got, expected := id, 1; got != expected {
					t.Errorf("CreateFn id = %d; expected %d", got, expected)
				}
				return nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRecordID, 1)
		err := RunRecordDelete(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:22,代码来源:domains_test.go

示例15: TestDomainsCreate

func TestDomainsCreate(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			CreateFn: func(req *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) {
				expected := &godo.DomainCreateRequest{
					Name:      testDomain.Name,
					IPAddress: "127.0.0.1",
				}
				if got := req; !reflect.DeepEqual(got, expected) {
					t.Errorf("CreateFn() called with %#v; expected %#v", got, expected)
				}
				return &testDomain, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgIPAddress, "127.0.0.1")
		err := RunDomainCreate(ns, c, ioutil.Discard, []string{testDomain.Name})
		assert.NoError(t, err)
	})
}
开发者ID:alexcb,项目名称:doit,代码行数:23,代码来源:domains_test.go


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