本文整理匯總了Golang中github.com/motain/gocheck.C.Errorf方法的典型用法代碼示例。如果您正苦於以下問題:Golang C.Errorf方法的具體用法?Golang C.Errorf怎麽用?Golang C.Errorf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/motain/gocheck.C
的用法示例。
在下文中一共展示了C.Errorf方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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")
}
}
}
示例2: 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.NewWithClient(s.ec2.Auth, r, testutil.DefaultClient)
_, 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")
}
}
}
示例3: WaitUntilStatus
func (s *DynamoDBTest) WaitUntilStatus(c *gocheck.C, status string) {
// We should wait until the table is in specified status because a real DynamoDB has some delay for ready
done := make(chan bool)
timeout := time.After(TIMEOUT)
go func() {
for {
select {
case <-done:
return
default:
desc, err := s.table.DescribeTable()
if err != nil {
c.Fatal(err)
}
if desc.TableStatus == status {
done <- true
return
}
time.Sleep(5 * time.Second)
}
}
}()
select {
case <-done:
break
case <-timeout:
c.Errorf("Expect a status to be %s, but timed out", status)
close(done)
}
}
示例4: TestMarshalEmptySets
func (s *MarshallerSuite) TestMarshalEmptySets(c *gocheck.C) {
testObj := testObjectWithEmptySets()
attrs, err := dynamodb.MarshalAttributes(testObj)
if err != nil {
c.Errorf("Error from dynamodb.MarshalAttributes: %#v", err)
}
expected := testAttrsWithNilSets()
c.Check(attrs, gocheck.DeepEquals, expected)
}
示例5: TestDeleteAutoScalingGroupWithExistingInstances
func (s *S) TestDeleteAutoScalingGroupWithExistingInstances(c *gocheck.C) {
testServer.Response(400, nil, DeleteAutoScalingGroupErrorResponse)
resp, err := s.as.DeleteAutoScalingGroup("my-test-asg", false)
testServer.WaitRequest()
c.Assert(resp, gocheck.IsNil)
c.Assert(err, gocheck.NotNil)
e, ok := err.(*Error)
if !ok {
c.Errorf("Unable to unmarshal error into AWS Autoscaling Error")
}
c.Assert(ok, gocheck.Equals, true)
c.Assert(e.Message, gocheck.Equals, "You cannot delete an AutoScalingGroup while there are instances or pending Spot instance request(s) still in the group.")
c.Assert(e.Code, gocheck.Equals, "ResourceInUse")
c.Assert(e.StatusCode, gocheck.Equals, 400)
c.Assert(e.RequestId, gocheck.Equals, "70a76d42-9665-11e2-9fdf-211deEXAMPLE")
}
示例6: TestDeleteLaunchConfigurationInUse
func (s *S) TestDeleteLaunchConfigurationInUse(c *gocheck.C) {
testServer.Response(400, nil, DeleteLaunchConfigurationInUseResponse)
resp, err := s.as.DeleteLaunchConfiguration("my-test-lc")
testServer.WaitRequest()
c.Assert(resp, gocheck.IsNil)
c.Assert(err, gocheck.NotNil)
e, ok := err.(*Error)
if !ok {
c.Errorf("Unable to unmarshal error into AWS Autoscaling Error")
}
c.Logf("%v %v %v", e.Code, e.Message, e.RequestId)
c.Assert(ok, gocheck.Equals, true)
c.Assert(e.Message, gocheck.Equals, "Cannot delete launch configuration my-test-lc because it is attached to AutoScalingGroup test")
c.Assert(e.Code, gocheck.Equals, "ResourceInUse")
c.Assert(e.StatusCode, gocheck.Equals, 400)
c.Assert(e.RequestId, gocheck.Equals, "7347261f-97df-11e2-8756-35eEXAMPLE")
}
示例7: TestAttemptTiming
func (S) TestAttemptTiming(c *gocheck.C) {
testAttempt := aws.AttemptStrategy{
Total: 0.25e9,
Delay: 0.1e9,
}
want := []time.Duration{0, 0.1e9, 0.2e9, 0.2e9}
got := make([]time.Duration, 0, len(want)) // avoid allocation when testing timing
t0 := time.Now()
for a := testAttempt.Start(); a.Next(); {
got = append(got, time.Now().Sub(t0))
}
got = append(got, time.Now().Sub(t0))
c.Assert(got, gocheck.HasLen, len(want))
const margin = 0.01e9
for i, got := range want {
lo := want[i] - margin
hi := want[i] + margin
if got < lo || got > hi {
c.Errorf("attempt %d want %g got %g", i, want[i].Seconds(), got.Seconds())
}
}
}
示例8: TestConditionalPutUpdateDeleteItem
func (s *ItemSuite) TestConditionalPutUpdateDeleteItem(c *gocheck.C) {
if s.WithRange {
// No rangekey test required
return
}
attrs := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "Attr1Val"),
}
pk := &dynamodb.Key{HashKey: "NewHashKeyVal"}
// Put
if ok, err := s.table.PutItem("NewHashKeyVal", "", attrs); !ok {
c.Fatal(err)
}
{
// Put with condition failed
expected := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "expectedAttr1Val").SetExists(true),
*dynamodb.NewStringAttribute("AttrNotExists", "").SetExists(false),
}
if ok, err := s.table.ConditionalPutItem("NewHashKeyVal", "", attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
} else {
c.Check(err.Error(), gocheck.Matches, "ConditionalCheckFailedException.*")
}
// Add attributes with condition failed
if ok, err := s.table.ConditionalAddAttributes(pk, attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
} else {
c.Check(err.Error(), gocheck.Matches, "ConditionalCheckFailedException.*")
}
// Update attributes with condition failed
if ok, err := s.table.ConditionalUpdateAttributes(pk, attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
} else {
c.Check(err.Error(), gocheck.Matches, "ConditionalCheckFailedException.*")
}
// Delete attributes with condition failed
if ok, err := s.table.ConditionalDeleteAttributes(pk, attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
} else {
c.Check(err.Error(), gocheck.Matches, "ConditionalCheckFailedException.*")
}
}
{
expected := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "Attr1Val").SetExists(true),
}
// Add attributes with condition met
addNewAttrs := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("AddNewAttr1", "10"),
*dynamodb.NewNumericAttribute("AddNewAttr2", "20"),
}
if ok, err := s.table.ConditionalAddAttributes(pk, addNewAttrs, nil); !ok {
c.Errorf("Expect condition met. %s", err)
}
// Update attributes with condition met
updateAttrs := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("AddNewAttr1", "100"),
}
if ok, err := s.table.ConditionalUpdateAttributes(pk, updateAttrs, expected); !ok {
c.Errorf("Expect condition met. %s", err)
}
// Delete attributes with condition met
deleteAttrs := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("AddNewAttr2", ""),
}
if ok, err := s.table.ConditionalDeleteAttributes(pk, deleteAttrs, expected); !ok {
c.Errorf("Expect condition met. %s", err)
}
// Get to verify operations that condition are met
item, err := s.table.GetItem(pk)
if err != nil {
c.Fatal(err)
}
if val, ok := item["AddNewAttr1"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("AddNewAttr1", "100"))
} else {
c.Error("Expect AddNewAttr1 attribute to be added and updated")
}
if _, ok := item["AddNewAttr2"]; ok {
c.Error("Expect AddNewAttr2 attribute to be deleted")
}
}
{
// Put with condition met
expected := []dynamodb.Attribute{
//.........這裏部分代碼省略.........