本文整理汇总了Golang中github.com/go-check/check.C.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang C.Error方法的具体用法?Golang C.Error怎么用?Golang C.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/go-check/check.C
的用法示例。
在下文中一共展示了C.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fetchStreamingResponse
func fetchStreamingResponse(t *check.C, url string) (*http.Response, string) {
// Create temp file for this unit test.
tmpFile, err := ioutil.TempFile("", "testfile_")
if err != nil {
t.Error(err)
}
err = tmpFile.Close()
if err != nil {
t.Error(err)
}
responseBody := []byte(fmt.Sprintf(`{"instance_path": "%s"}`, tmpFile.Name()))
fc := func(w http.ResponseWriter, r *http.Request) {
w.Write(responseBody)
}
lc, hc, pc := startTestServer(http.HandlerFunc(fc))
defer lc.Close()
h := handler{
deaHost: hc,
deaPort: pc,
streamingTimeout: 1,
deaClient: &DeaClient{Host: hc, Port: pc},
}
ld, hd, pd := startTestServer(h)
defer ld.Close()
// Start writing content to the temp file in a separate thread.
go dump(tmpFile, t, 10) // thread.
time.Sleep(1 * time.Second)
response, err := http.Get(fmt.Sprintf("http://%s:%d%s", hd, pd, url))
if err != nil {
t.Error(err)
}
body := make([]byte, 100)
_, err = response.Body.Read(body)
if err != nil {
// If no data comes through before timeout expires
// stream handler will just close the connection
// causing EOF error which is ok.
if err != io.EOF && err != io.ErrUnexpectedEOF {
t.Error(err)
}
}
if err = os.Remove(tmpFile.Name()); err != nil {
t.Error(err)
}
return response, string(body)
}
示例2: SetUpTest
func (s *MySuite) SetUpTest(c *check.C) {
dir, _ := os.Getwd()
c.Log("Entering setup in directory", dir)
common.MockPortsInConfig("../common/testdata/romana.sample.yaml")
s.configFile = "/tmp/romana.yaml"
var err error
s.config, err = common.ReadConfig(s.configFile)
if err != nil {
panic(err)
}
c.Log("Root configuration: ", s.config.Services["root"].Common.Api.GetHostPort())
// Starting root service
fmt.Println("STARTING ROOT SERVICE")
channelRoot, addr, err := root.Run(s.configFile)
if err != nil {
c.Error(err)
}
s.rootUrl = "http://" + addr
c.Log("Root URL:", s.rootUrl)
msg := <-channelRoot
c.Log("Root service said:", msg)
c.Log("Waiting a bit...")
time.Sleep(time.Second)
c.Log("Creating topology schema with root URL", s.rootUrl)
err = topology.CreateSchema(s.rootUrl, true)
if err != nil {
c.Fatal(err)
}
c.Log("OK")
c.Log("Creating tenant schema")
err = tenant.CreateSchema(s.rootUrl, true)
if err != nil {
c.Fatal(err)
}
c.Log("OK")
c.Log("Creating IPAM schema")
err = ipam.CreateSchema(s.rootUrl, true)
if err != nil {
c.Fatal(err)
}
c.Log("OK")
myLog(c, "Done with setup")
}
示例3: dump
func dump(file *os.File, t *check.C, numLines int) error {
handle, err := os.OpenFile(file.Name(), syscall.O_WRONLY, 0666)
if err != nil {
t.Error(err)
}
for i := 0; i < numLines; i++ {
_, err = handle.WriteString(fmt.Sprintf("blah%d", i))
if err != nil {
t.Error(err)
}
time.Sleep(250 * time.Millisecond)
}
err = handle.Close()
return err
}
示例4: TestHandler_ServeHTTP_EntityNotFound
func (s *DirectoryServerSuite) TestHandler_ServeHTTP_EntityNotFound(t *check.C) {
responseBody := []byte("{\"instance_path\" : \"dummy\"}")
fc := func(w http.ResponseWriter, r *http.Request) {
w.Write(responseBody)
}
lc, hc, pc := startTestServer(http.HandlerFunc(fc))
defer lc.Close()
h := handler{
deaHost: hc,
deaPort: pc,
streamingTimeout: 1,
deaClient: &DeaClient{Host: hc, Port: pc},
}
ld, hd, pd := startTestServer(h)
defer ld.Close()
response, err := http.Get(fmt.Sprintf("http://%s:%d/path", hd, pd))
if err != nil {
t.Error(err)
}
// Check status code.
if response.StatusCode != 400 {
t.Fail()
}
// Check headers.
if response.Header.Get("Content-Type") != "text/plain" {
t.Fail()
}
if response.Header.Get("X-Cascade") != "pass" {
t.Fail()
}
// Check body.
body, err := getBody(response)
if err != nil {
t.Error(err)
}
if strings.ToLower(string(body)) != "entity not found.\n" {
t.Fail()
}
}
示例5: assertPortList
func assertPortList(c *check.C, out string, expected []string) bool {
//lines := strings.Split(out, "\n")
lines := strings.Split(strings.Trim(out, "\n "), "\n")
if len(lines) != len(expected) {
c.Errorf("different size lists %s, %d, %d", out, len(lines), len(expected))
return false
}
sort.Strings(lines)
sort.Strings(expected)
for i := 0; i < len(expected); i++ {
if lines[i] != expected[i] {
c.Error("|" + lines[i] + "!=" + expected[i] + "|")
return false
}
}
return true
}
示例6: TestPortHostBinding
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
"nc", "-l", "-p", "80")
firstID := strings.TrimSpace(out)
out, _ = dockerCmd(c, "port", firstID, "80")
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct")
}
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
dockerCmd(c, "rm", "-f", firstID)
if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
"nc", "localhost", "9876"); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}
示例7: TestHandler_ServeHTTP_RequestDeniedByDea
func (s *DirectoryServerSuite) TestHandler_ServeHTTP_RequestDeniedByDea(t *check.C) {
responseBody := []byte("{\"instance_path\" : \"dummy\"}")
fc := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
w.Write(responseBody)
}
lc, hc, pc := startTestServer(http.HandlerFunc(fc))
defer lc.Close()
h := handler{
deaHost: hc,
deaPort: pc,
streamingTimeout: 1,
deaClient: &DeaClient{Host: hc, Port: pc},
}
ld, hd, pd := startTestServer(h)
defer ld.Close()
response, err := http.Get(fmt.Sprintf("http://%s:%d/path", hd, pd))
if err != nil {
t.Error(err)
}
// Check status code.
if response.StatusCode != 400 {
t.Fail()
}
// Check body.
body, err := getBody(response)
if err != nil {
t.Error(err)
}
if bytes.Compare(body, responseBody) != 0 {
t.Fail()
}
}
示例8: TestExecWindowsOpenHandles
func (s *DockerSuite) TestExecWindowsOpenHandles(c *check.C) {
testRequires(c, DaemonIsWindows)
runSleepingContainer(c, "-d", "--name", "test")
exec := make(chan bool)
go func() {
dockerCmd(c, "exec", "test", "cmd", "/c", "start sleep 10")
exec <- true
}()
for {
top := make(chan string)
var out string
go func() {
out, _ := dockerCmd(c, "top", "test")
top <- out
}()
select {
case <-time.After(time.Second * 5):
c.Error("timed out waiting for top while exec is exiting")
case out = <-top:
break
}
if strings.Count(out, "busybox.exe") == 2 && !strings.Contains(out, "cmd.exe") {
// The initial exec process (cmd.exe) has exited, and both sleeps are currently running
break
}
time.Sleep(1 * time.Second)
}
inspect := make(chan bool)
go func() {
dockerCmd(c, "inspect", "test")
inspect <- true
}()
select {
case <-time.After(time.Second * 5):
c.Error("timed out waiting for inspect while exec is exiting")
case <-inspect:
break
}
// Ensure the background sleep is still running
out, _ := dockerCmd(c, "top", "test")
c.Assert(strings.Count(out, "busybox.exe"), checker.Equals, 2)
// The exec should exit when the background sleep exits
select {
case <-time.After(time.Second * 15):
c.Error("timed out waiting for async exec to exit")
case <-exec:
// Ensure the background sleep has actually exited
out, _ := dockerCmd(c, "top", "test")
c.Assert(strings.Count(out, "busybox.exe"), checker.Equals, 1)
break
}
}
示例9: SetUpTest
func (s *MySuite) SetUpTest(c *check.C) {
myLog(c, "Entering SetUP, services started: ", s.servicesStarted)
if !s.servicesStarted {
dir, _ := os.Getwd()
myLog(c, "Entering setup in directory", dir)
var err error
err = s.RomanaTestSuite.MockConfig(common.DefaultTestConfigFile)
if err != nil {
panic(err)
}
myLog(c, "Root configuration: ", s.RomanaTestSuite.Config.Services["root"].Common.Api.GetHostPort())
root.Run(s.RomanaTestSuite.ConfigFile)
// Starting root service
myLog(c, "Starting root service...")
svcInfo, err := root.Run(s.RomanaTestSuite.ConfigFile)
if err != nil {
c.Error(err)
}
s.rootURL = "http://" + svcInfo.Address
myLog(c, "Root URL:", s.rootURL)
msg := <-svcInfo.Channel
myLog(c, "Root service said:", msg)
myLog(c, "Creating topology schema")
topoSvc := &TopologySvc{}
err = common.SimpleOverwriteSchema(topoSvc, s.rootURL)
myLog(c, "CreateSchema returned err: ", err, "which is of type", reflect.TypeOf(err), "let's compare it to", nil, ": err != nil: ", err != nil)
if err != nil {
c.Fatal(err)
}
s.servicesStarted = true
myLog(c, "Done with setup")
}
}
示例10: SetUpTest
func (s *MySuite) SetUpTest(c *check.C) {
myLog(c, "Entering SetUP, services started: ", s.servicesStarted)
if !s.servicesStarted {
dir, _ := os.Getwd()
myLog(c, "Entering setup in directory", dir)
common.MockPortsInConfig("../common/testdata/romana.sample.yaml")
s.configFile = "/tmp/romana.yaml"
var err error
s.config, err = common.ReadConfig(s.configFile)
if err != nil {
panic(err)
}
myLog(c, "Root configuration: ", s.config.Services["root"].Common.Api.GetHostPort())
root.Run(s.configFile)
// Starting root service
myLog(c, "Starting root service...")
channelRoot, addr, err := root.Run(s.configFile)
if err != nil {
c.Error(err)
}
s.rootUrl = "http://" + addr
myLog(c, "Root URL:", s.rootUrl)
msg := <-channelRoot
myLog(c, "Root service said:", msg)
myLog(c, "Creating topology schema")
err = CreateSchema(s.rootUrl, true)
myLog(c, "CreateSchema returned err: ", err, "which is of type", reflect.TypeOf(err), "let's compare it to", nil, ": err != nil: ", err != nil)
if err != nil {
c.Fatal(err)
}
s.servicesStarted = true
myLog(c, "Done with setup")
}
}
示例11: TestPortExposeHostBinding
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox",
"nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
_, exposedPort, err := net.SplitHostPort(out)
if err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}
示例12: TestTopology
// Test the topology service
func (s *MySuite) TestTopology(c *check.C) {
myLog(c, "Entering TestTopology()")
dir, _ := os.Getwd()
myLog(c, "In", dir)
myLog(c, "Starting topology service")
channelTop, addr, err := Run(s.rootUrl)
if err != nil {
c.Error(err)
}
msg := <-channelTop
myLog(c, "Topology service said:", msg)
addr = "http://" + addr
client, err := common.NewRestClient(addr, common.DefaultRestTimeout)
if err != nil {
c.Error(err)
}
myLog(c, "Calling ", addr)
topIndex := &common.IndexResponse{}
err = client.Get("/", &topIndex)
if err != nil {
c.Error(err)
}
c.Assert(topIndex.ServiceName, check.Equals, "topology")
hostsRelUrl := topIndex.Links.FindByRel("host-list")
hostsUrl := addr + hostsRelUrl
myLog(c, "Host list URL: ", hostsUrl)
// Get list of hosts - should be empty for now.
var hostList []Host
client.Get(hostsRelUrl, &hostList)
myLog(c, "Host list: ", hostList)
c.Assert(len(hostList), check.Equals, 0)
newHostReq := common.HostMessage{Ip: "10.10.10.10", AgentPort: 9999, Name: "host10"}
newHostResp := common.HostMessage{}
client.Post(hostsRelUrl, newHostReq, &newHostResp)
myLog(c, "Response: ", newHostResp)
c.Assert(newHostResp.Ip, check.Equals, "10.10.10.10")
c.Assert(newHostResp.Id, check.Equals, "1")
newHostReq = common.HostMessage{Ip: "10.10.10.11", AgentPort: 9999, Name: "host11"}
newHostResp = common.HostMessage{}
client.Post(hostsRelUrl, newHostReq, &newHostResp)
myLog(c, "Response: ", newHostResp)
c.Assert(newHostResp.Ip, check.Equals, "10.10.10.11")
c.Assert(newHostResp.Id, check.Equals, "2")
var hostList2 []Host
client.Get(hostsRelUrl, &hostList2)
myLog(c, "Host list: ", hostList2)
c.Assert(len(hostList2), check.Equals, 2)
}
示例13: TestHandler_ServeHTTP_RequestToDeaFailed
func (s *DirectoryServerSuite) TestHandler_ServeHTTP_RequestToDeaFailed(t *check.C) {
lc, hc, pc := startTestServer(http.NotFoundHandler())
lc.Close()
h := handler{
deaHost: hc,
deaPort: pc,
streamingTimeout: 1,
deaClient: &DeaClient{Host: hc, Port: pc},
}
ld, hd, pd := startTestServer(h)
defer ld.Close()
response, err := http.Get(fmt.Sprintf("http://%s:%d/path", hd, pd))
if err != nil {
t.Error(err)
}
if response.StatusCode != 500 {
t.Fail()
}
}
示例14: TestHostMarshaling
// TestHostMarshaling tests marshaling/unmarshaling of Host
// structure to/from proper JSON.
func (s *MySuite) TestHostMarshaling(c *check.C) {
host := common.Host{}
host.ID = 1
host.RomanaIp = "192.168.0.1/16"
host.Ip = "10.1.1.1"
host.Name = "host1"
host.AgentPort = 9999
m := common.ContentTypeMarshallers["application/json"]
json, _ := m.Marshal(host)
marshaledJSONStr := string(json)
myLog(c, "Marshaled ", host, "to", marshaledJSONStr)
expectedJSONStr := "{\"id\":1,\"name\":\"host1\",\"ip\":\"10.1.1.1\",\"romana_ip\":\"192.168.0.1/16\",\"agent_port\":9999}"
c.Assert(marshaledJSONStr, check.Equals, expectedJSONStr)
host2 := common.Host{}
err := m.Unmarshal([]byte(expectedJSONStr), &host2)
if err != nil {
c.Error(err)
}
c.Assert(host2.ID, check.Equals, uint64(1))
c.Assert(host2.Ip, check.Equals, "10.1.1.1")
c.Assert(host2.RomanaIp, check.Equals, "192.168.0.1/16")
c.Assert(host2.AgentPort, check.Equals, uint64(9999))
}
示例15: TestPortExposeHostBinding
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
"nc", "-l", "-p", "80")
firstID := strings.TrimSpace(out)
out, _ = dockerCmd(c, "port", firstID, "80")
_, exposedPort, err := net.SplitHostPort(out)
if err != nil {
c.Fatal(out, err)
}
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
dockerCmd(c, "rm", "-f", firstID)
if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}