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


Golang C.Errorf方法代码示例

本文整理汇总了Golang中launchpad/net/gocheck.C.Errorf方法的典型用法代码示例。如果您正苦于以下问题:Golang C.Errorf方法的具体用法?Golang C.Errorf怎么用?Golang C.Errorf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在launchpad/net/gocheck.C的用法示例。


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

示例1: TestExportEnvironmentsBackward

func (s *S) TestExportEnvironmentsBackward(c *gocheck.C) {
	envNames := []string{
		"TSURU_S3_ACCESS_KEY_ID", "TSURU_S3_SECRET_KEY",
		"TSURU_APPNAME", "TSURU_HOST", "TSURU_S3_ENDPOINT",
		"TSURU_S3_LOCATIONCONSTRAINT", "TSURU_S3_BUCKET",
		"TSURU_APP_TOKEN",
	}
	app := App{Name: "moon", Platform: "opeth", Env: make(map[string]bind.EnvVar)}
	for _, name := range envNames {
		envVar := bind.EnvVar{Name: name, Value: name, Public: false}
		if strings.HasPrefix(name, "TSURU_S3_") {
			envVar.InstanceName = s3InstanceName
		}
		app.Env[name] = envVar
	}
	token, err := auth.CreateApplicationToken(app.Name)
	c.Assert(err, gocheck.IsNil)
	app.Env["TSURU_APP_TOKEN"] = bind.EnvVar{Name: "TSURU_APP_NAME", Value: token.Token}
	err = s.conn.Apps().Insert(app)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": app.Name})
	ctx := action.BWContext{Params: []interface{}{&app}}
	exportEnvironmentsAction.Backward(ctx)
	copy, err := GetByName(app.Name)
	c.Assert(err, gocheck.IsNil)
	for _, name := range envNames {
		if _, ok := copy.Env[name]; ok {
			c.Errorf("Variable %q should be unexported, but it's still exported.", name)
		}
	}
	_, err = auth.GetToken("bearer " + token.Token)
	c.Assert(err, gocheck.Equals, auth.ErrInvalidToken)
}
开发者ID:rpeterson,项目名称:tsuru,代码行数:33,代码来源:actions_test.go

示例2: TestStopInstances

func (t *LiveTests) TestStopInstances(c *gc.C) {
	// It would be nice if this test was in jujutest, but
	// there's no way for jujutest to fabricate a valid-looking
	// instance id.
	inst0, _ := testing.AssertStartInstance(c, t.Env, "40")
	inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa")
	inst2, _ := testing.AssertStartInstance(c, t.Env, "41")

	err := t.Env.StopInstances(inst0.Id(), inst1.Id(), inst2.Id())
	c.Check(err, gc.IsNil)

	var insts []instance.Instance

	// We need the retry logic here because we are waiting
	// for Instances to return an error, and it will not retry
	// if it succeeds.
	gone := false
	for a := ec2.ShortAttempt.Start(); a.Next(); {
		insts, err = t.Env.Instances([]instance.Id{inst0.Id(), inst2.Id()})
		if err == environs.ErrPartialInstances {
			// instances not gone yet.
			continue
		}
		if err == environs.ErrNoInstances {
			gone = true
			break
		}
		c.Fatalf("error getting instances: %v", err)
	}
	if !gone {
		c.Errorf("after termination, instances remaining: %v", insts)
	}
}
开发者ID:jiasir,项目名称:juju,代码行数:33,代码来源:live_test.go

示例3: TriggerChange

func (tw *TestWatcher) TriggerChange(c *gc.C) {
	select {
	case tw.changes <- struct{}{}:
	case <-time.After(coretesting.LongWait):
		c.Errorf("Timeout changes triggering change after %s", coretesting.LongWait)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:notifyworker_test.go

示例4: TestPingCalledOnceOnlyForSeveralWorkers

func (s *singularSuite) TestPingCalledOnceOnlyForSeveralWorkers(c *gc.C) {
	// Patch the ping interval to a large value, start several workers
	// and check that Ping is only called once.
	s.PatchValue(&singular.PingInterval, testing.LongWait)

	underlyingRunner := newRunner()
	conn := &fakeConn{
		isMaster: false,
		pinged:   make(chan struct{}, 2),
	}

	r, err := singular.New(underlyingRunner, conn)
	c.Assert(err, gc.IsNil)

	for i := 0; i < 5; i++ {
		name := fmt.Sprint("worker", i)
		err := r.StartWorker(name, func() (worker.Worker, error) {
			c.Errorf("worker unexpectedly started")
			return nil, fmt.Errorf("no worker")
		})
		c.Assert(err, gc.IsNil)
	}
	time.Sleep(testing.ShortWait)
	n := 0
loop:
	for {
		select {
		case <-conn.pinged:
			n++
		default:
			break loop
		}
	}
	c.Assert(n, gc.Equals, 1)
}
开发者ID:jameinel,项目名称:core,代码行数:35,代码来源:singular_test.go

示例5: TestRegions

// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *gocheck.C) {
	name := sessionName("goamz-region-test")
	perms := []ec2.IPPerm{{
		Protocol:  "tcp",
		FromPort:  80,
		ToPort:    80,
		SourceIPs: []string{"127.0.0.1/32"},
	}}
	errs := make(chan error, len(allRegions))
	for _, region := range allRegions {
		go func(r aws.Region) {
			e := ec2.New(s.ec2.Auth, r)
			_, err := e.AuthorizeSecurityGroup(ec2.SecurityGroup{Name: name}, perms)
			errs <- err
		}(region)
	}
	for _ = range allRegions {
		err := <-errs
		if err != nil {
			ec2_err, ok := err.(*ec2.Error)
			if ok {
				c.Check(ec2_err.Code, gocheck.Matches, "InvalidGroup.NotFound")
			} else {
				c.Errorf("Non-EC2 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
开发者ID:hailocab,项目名称:goamz,代码行数:31,代码来源:ec2i_test.go

示例6: TestWatchInitialEventConsumed

func (s *watcherSuite) TestWatchInitialEventConsumed(c *gc.C) {
	// Machiner.Watch should send the initial event as part of the Watch
	// call (for NotifyWatchers there is no state to be transmitted). So a
	// call to Next() should not have anything to return.
	var results params.NotifyWatchResults
	args := params.Entities{Entities: []params.Entity{{Tag: s.rawMachine.Tag().String()}}}
	err := s.stateAPI.Call("Machiner", "", "Watch", args, &results)
	c.Assert(err, gc.IsNil)
	c.Assert(results.Results, gc.HasLen, 1)
	result := results.Results[0]
	c.Assert(result.Error, gc.IsNil)

	// We expect the Call() to "Next" to block, so run it in a goroutine.
	done := make(chan error)
	go func() {
		ignored := struct{}{}
		done <- s.stateAPI.Call("NotifyWatcher", result.NotifyWatcherId, "Next", nil, &ignored)
	}()

	select {
	case err := <-done:
		c.Errorf("Call(Next) did not block immediately after Watch(): err %v", err)
	case <-time.After(coretesting.ShortWait):
	}
}
开发者ID:jiasir,项目名称:juju,代码行数:25,代码来源:watcher_test.go

示例7: TestUnitListState

func (s *S) TestUnitListState(c *gocheck.C) {
	var tests = []struct {
		input    []Unit
		expected string
	}{
		{
			[]Unit{{State: "started"}, {State: "started"}}, "started",
		},
		{nil, ""},
		{
			[]Unit{{State: "started"}, {State: "pending"}}, "",
		},
		{
			[]Unit{{State: "error"}}, "error",
		},
		{
			[]Unit{{State: "pending"}}, "pending",
		},
	}
	for _, t := range tests {
		l := unitList(t.input)
		if got := l.State(); got != t.expected {
			c.Errorf("l.State(): want %q. Got %q.", t.expected, got)
		}
	}
}
开发者ID:nightshade427,项目名称:tsuru,代码行数:26,代码来源:queue_test.go

示例8: TestWriteFailure

func (s *storageSuite) TestWriteFailure(c *gc.C) {
	// Invocations:
	//  1: first "install"
	//  2: touch, Put
	//  3: second "install"
	//  4: touch
	var invocations int
	badSshCommand := func(host string, command ...string) *ssh.Cmd {
		invocations++
		switch invocations {
		case 1, 3:
			return s.sshCommand(c, host, "true")
		case 2:
			// Note: must close stdin before responding the first time, or
			// the second command will race with closing stdin, and may
			// flush first.
			return s.sshCommand(c, host, "head -n 1 > /dev/null; exec 0<&-; echo JUJU-RC: 0; echo blah blah; echo more")
		case 4:
			return s.sshCommand(c, host, `head -n 1 > /dev/null; echo "Hey it's JUJU-RC: , but not at the beginning of the line"; echo more`)
		default:
			c.Errorf("unexpected invocation: #%d, %s", invocations, command)
			return nil
		}
	}
	s.PatchValue(&sshCommand, badSshCommand)

	stor, err := newSSHStorage("example.com", c.MkDir(), c.MkDir())
	c.Assert(err, gc.IsNil)
	defer stor.Close()
	err = stor.Put("whatever", bytes.NewBuffer(nil), 0)
	c.Assert(err, gc.ErrorMatches, `failed to write input: write \|1: broken pipe \(output: "blah blah\\nmore"\)`)

	_, err = newSSHStorage("example.com", c.MkDir(), c.MkDir())
	c.Assert(err, gc.ErrorMatches, `failed to locate "JUJU-RC: " \(output: "Hey it's JUJU-RC: , but not at the beginning of the line\\nmore"\)`)
}
开发者ID:jameinel,项目名称:core,代码行数:35,代码来源:storage_test.go

示例9: checkInteger

func checkInteger(elem interface{}, expected int64, c *gc.C) {
	if num, is_num := elem.(Integer); is_num {
		c.Check(num.ToInteger(), gc.Equals, expected)
	} else {
		c.Errorf("actual value is not an Integer: %T", elem)
	}
}
开发者ID:nlfiedler,项目名称:bakeneko,代码行数:7,代码来源:interpreter_test.go

示例10: TestRegions

// Communicate with all endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *gocheck.C) {
	errs := make(chan error, len(aws.Regions))
	for _, region := range aws.Regions {
		go func(r aws.Region) {
			s := s3.New(s.s3.Auth, r)
			b := s.Bucket("goamz-" + s.Auth.AccessKey)
			_, err := b.Get("non-existent")
			errs <- err
		}(region)
	}
	for _ = range aws.Regions {
		err := <-errs
		if err != nil {
			s3_err, ok := err.(*s3.Error)
			if ok {
				c.Check(s3_err.Code, gocheck.Matches, "NoSuchBucket")
			} else if _, ok = err.(*net.DNSError); ok {
				// Okay as well.
			} else {
				c.Errorf("Non-S3 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
开发者ID:hailocab,项目名称:goamz,代码行数:27,代码来源:s3i_test.go

示例11: TestUnitListStarted

func (s *S) TestUnitListStarted(c *gocheck.C) {
	var tests = []struct {
		input    []Unit
		expected bool
	}{
		{
			[]Unit{
				{State: "started"},
				{State: "started"},
				{State: "started"},
			},
			true,
		},
		{nil, true},
		{
			[]Unit{
				{State: "started"},
				{State: "blabla"},
			},
			false,
		},
	}
	for _, t := range tests {
		l := unitList(t.input)
		if got := l.Started(); got != t.expected {
			c.Errorf("l.Started(): want %v. Got %v.", t.expected, got)
		}
	}
}
开发者ID:nihao,项目名称:tsuru,代码行数:29,代码来源:queue_test.go

示例12: TestLongContainerName

func (s *IntegrationTestSuite) TestLongContainerName(c *chk.C) {
	id, err := containers.NewIdentifier("IntTest006xxxxxxxxxxxxxx")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId, "--start", "--ports=8080:0", "--isolate")
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerStarts(c, id)

	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)
	s.assertFilePresent(c, filepath.Join(id.RunPathFor(), "container-init.sh"), 0700, false)

	ports, err := containers.GetExistingPorts(id)
	c.Assert(err, chk.IsNil)
	c.Assert(len(ports), chk.Equals, 1)

	httpAlive := func() bool {
		resp, err := http.Get(fmt.Sprintf("http://0.0.0.0:%v", ports[0].External))
		if err == nil {
			c.Assert(resp.StatusCode, chk.Equals, 200)
			return true
		}
		return false
	}
	if !until(TimeoutContainerStateChange, IntervalHttpCheck, httpAlive) {
		c.Errorf("Unable to retrieve a 200 status code from port %d", ports[0].External)
		c.FailNow()
	}
}
开发者ID:jhadvig,项目名称:geard,代码行数:33,代码来源:integration_test.go

示例13: assertContainerStartsAndExits

func (s *IntegrationTestSuite) assertContainerStartsAndExits(c *chk.C, start time.Time, id containers.Identifier) {
	hasStarted := func() bool {
		_, inactiveEnd, activeStart, _ := s.unitTimes(id)
		if inactiveEnd.IsZero() || activeStart.IsZero() {
			c.Logf("Variables empty before")
		}
		if inactiveEnd.Before(start) || activeStart.Before(start) {
			return false
		}
		return true
	}
	if !until(TimeoutContainerStateChange, IntervalContainerCheck, hasStarted) {
		c.Errorf("The service did not start in the allotted time")
		c.FailNow()
	}

	hasCompleted := func() bool {
		switch active, _ := s.unitState(id); active {
		case "active", "activating", "deactivating":
			return false
		}
		return true
	}
	if !until(TimeoutContainerStateChange, IntervalContainerCheck, hasCompleted) {
		c.Errorf("The service did not finish in the allotted time")
		c.FailNow()
	}
}
开发者ID:jhadvig,项目名称:geard,代码行数:28,代码来源:integration_test.go

示例14: TestIsValid

func (s *S) TestIsValid(c *gocheck.C) {
	var data = []struct {
		name     string
		expected bool
	}{
		{"myappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyapp", false},
		{"myappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyap", false},
		{"myappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmyappmya", true},
		{"myApp", false},
		{"my app", false},
		{"123myapp", false},
		{"myapp", true},
		{"_theirapp", false},
		{"my-app", true},
		{"-myapp", false},
		{"my_app", false},
		{"b", true},
	}
	for _, d := range data {
		a := App{Name: d.name}
		if valid := a.isValid(); valid != d.expected {
			c.Errorf("Is %q a valid app name? Expected: %v. Got: %v.", d.name, d.expected, valid)
		}
	}
}
开发者ID:nedmax,项目名称:tsuru,代码行数:25,代码来源:app_test.go

示例15: TestAddWatcher

func (s *ManagerTestSuite) TestAddWatcher(t *gocheck.C) {
	now = int64(1380330697385120263) // Fri Sep 27 18:11:37.385120 -0700 PDT 2013
	s.tickerFactory.Set([]ticker.Ticker{s.mockTicker})

	m := ticker.NewClock(s.tickerFactory, nowFunc)

	c := make(chan time.Time)
	m.Add(c, 79, true)

	if !test.WaitState(s.mockTicker.RunningChan) {
		t.Error("Starts ticker")
	}

	if ok, diff := test.IsDeeply(s.tickerFactory.Made, []uint{79}); !ok {
		t.Errorf("Make 79s ticker, got %#v", diff)
	}

	if len(s.mockTicker.Added) == 0 {
		t.Error("Ticker added watcher")
	}

	// Manager should call ticker's ETA() to return time to next tick.
	d := m.ETA(c)
	if d != 0.1 {
		t.Error("clock.Manager.ETA()")
	}

	m.Remove(c)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:29,代码来源:ticker_test.go


注:本文中的launchpad/net/gocheck.C.Errorf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。