本文整理匯總了Golang中github.com/motain/gocheck.C.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang C.Error方法的具體用法?Golang C.Error怎麽用?Golang C.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/motain/gocheck.C
的用法示例。
在下文中一共展示了C.Error方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TearDownSuite
func (s *DynamoDBTest) TearDownSuite(c *gocheck.C) {
// return immediately in the case of calling c.Skip() in SetUpSuite()
if s.server == nil {
return
}
// check whether the table exists
if tables, err := s.server.ListTables(); err != nil {
c.Fatal(err)
} else {
if !findTableByName(tables, s.TableDescriptionT.TableName) {
return
}
}
// Delete the table and wait
if _, err := s.server.DeleteTable(s.TableDescriptionT); err != nil {
c.Fatal(err)
}
done := make(chan bool)
timeout := time.After(TIMEOUT)
go func() {
for {
select {
case <-done:
return
default:
tables, err := s.server.ListTables()
if err != nil {
c.Fatal(err)
}
if findTableByName(tables, s.TableDescriptionT.TableName) {
time.Sleep(5 * time.Second)
} else {
done <- true
return
}
}
}
}()
select {
case <-done:
break
case <-timeout:
c.Error("Expect the table to be deleted but timed out")
close(done)
}
}
示例2: TestPutGetDeleteItem
func (s *ItemSuite) TestPutGetDeleteItem(c *gocheck.C) {
attrs := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "Attr1Val"),
}
var rk string
if s.WithRange {
rk = "1"
}
// Put
if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
c.Fatal(err)
}
// Get to verify Put operation
pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
item, err := s.table.GetItem(pk)
if err != nil {
c.Fatal(err)
}
if val, ok := item["TestHashKey"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewStringAttribute("TestHashKey", "NewHashKeyVal"))
} else {
c.Error("Expect TestHashKey to be found")
}
if s.WithRange {
if val, ok := item["TestRangeKey"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("TestRangeKey", "1"))
} else {
c.Error("Expect TestRangeKey to be found")
}
}
// Delete
if ok, _ := s.table.DeleteItem(pk); !ok {
c.Fatal(err)
}
// Get to verify Delete operation
_, err = s.table.GetItem(pk)
c.Check(err.Error(), gocheck.Matches, "Item not found")
}
示例3: TestCreateListTable
func (s *TableSuite) TestCreateListTable(c *gocheck.C) {
status, err := s.server.CreateTable(s.TableDescriptionT)
if err != nil {
c.Fatal(err)
}
if status != "ACTIVE" && status != "CREATING" {
c.Error("Expect status to be ACTIVE or CREATING")
}
s.WaitUntilStatus(c, "ACTIVE")
tables, err := s.server.ListTables()
if err != nil {
c.Fatal(err)
}
c.Check(len(tables), gocheck.Not(gocheck.Equals), 0)
c.Check(findTableByName(tables, s.TableDescriptionT.TableName), gocheck.Equals, true)
}
示例4: 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{
//.........這裏部分代碼省略.........
示例5: TestUpdateItemWithSet
func (s *ItemSuite) TestUpdateItemWithSet(c *gocheck.C) {
attrs := []dynamodb.Attribute{
*dynamodb.NewStringSetAttribute("list", []string{"A", "B"}),
}
var rk string
if s.WithRange {
rk = "1"
}
if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
c.Error(err)
}
// UpdateItem with Add
attrs = []dynamodb.Attribute{
*dynamodb.NewStringSetAttribute("list", []string{"C"}),
}
pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
if ok, err := s.table.AddAttributes(pk, attrs); !ok {
c.Error(err)
}
// Get to verify Add operation
if item, err := s.table.GetItem(pk); err != nil {
c.Error(err)
} else {
if val, ok := item["list"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewStringSetAttribute("list", []string{"A", "B", "C"}))
} else {
c.Error("Expect count to be found")
}
}
// UpdateItem with Delete
attrs = []dynamodb.Attribute{
*dynamodb.NewStringSetAttribute("list", []string{"A"}),
}
if ok, err := s.table.DeleteAttributes(pk, attrs); !ok {
c.Error(err)
}
// Get to verify Delete operation
if item, err := s.table.GetItem(pk); err != nil {
c.Error(err)
} else {
if val, ok := item["list"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewStringSetAttribute("list", []string{"B", "C"}))
} else {
c.Error("Expect list to be remained")
}
}
}
示例6: TestUpdateItem
func (s *ItemSuite) TestUpdateItem(c *gocheck.C) {
attrs := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("count", "0"),
}
var rk string
if s.WithRange {
rk = "1"
}
if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
c.Fatal(err)
}
// UpdateItem with Add
attrs = []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("count", "10"),
}
pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
if ok, err := s.table.AddAttributes(pk, attrs); !ok {
c.Error(err)
}
// Get to verify Add operation
if item, err := s.table.GetItemConsistent(pk, true); err != nil {
c.Error(err)
} else {
if val, ok := item["count"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("count", "10"))
} else {
c.Error("Expect count to be found")
}
}
// UpdateItem with Put
attrs = []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("count", "100"),
}
if ok, err := s.table.UpdateAttributes(pk, attrs); !ok {
c.Error(err)
}
// Get to verify Put operation
if item, err := s.table.GetItem(pk); err != nil {
c.Fatal(err)
} else {
if val, ok := item["count"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("count", "100"))
} else {
c.Error("Expect count to be found")
}
}
// UpdateItem with Delete
attrs = []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("count", ""),
}
if ok, err := s.table.DeleteAttributes(pk, attrs); !ok {
c.Error(err)
}
// Get to verify Delete operation
if item, err := s.table.GetItem(pk); err != nil {
c.Error(err)
} else {
if _, ok := item["count"]; ok {
c.Error("Expect count not to be found")
}
}
}