github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoints/delete_item/delete_item_test.go (about) 1 package delete_item 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 func TestNil(t *testing.T) { 10 d := NewDeleteItem() 11 _,_,err := d.EndpointReqWithConf(nil) 12 if err == nil { 13 t.Errorf("nil conf should result in error") 14 } 15 } 16 17 func TestRequestUnmarshal(t *testing.T) { 18 s := []string{ 19 `{"TableName":"Thread","Key":{"ForumName":{"S":"AmazonDynamoDB"},"Subject":{"S":"HowdoIupdatemultipleitems?"}},"Expected":{"Replies":{"AttributeValueList":null,"Exists":false}},"ReturnValues":"ALL_OLD"}`, `{"TableName":"Thread","Key":{"ForumName":{"S":"AmazonDynamoDB"},"Subject":{"S":"HowdoIupdatemultipleitems?"}}}`, 20 } 21 for _, v := range s { 22 d := NewDeleteItem() 23 um_err := json.Unmarshal([]byte(v), d) 24 if um_err != nil { 25 _ = fmt.Sprintf("%v\n", um_err) 26 t.Errorf("cannot unmarshal to delete:\n" + v + "\n") 27 } 28 _, jerr := json.Marshal(d) 29 if jerr != nil { 30 t.Errorf("cannot marshal\n") 31 } 32 } 33 } 34 35 func TestResponseUnmarshal(t *testing.T) { 36 s := []string{`{"Attributes":{"LastPostedBy":{"S":"fred@example.com"},"ForumName":{"S":"AmazonDynamoDB"},"LastPostDateTime":{"S":"201303201023"},"Tags":{"SS":["Update","MultipleItems","HelpMe"]},"Subject":{"S":"HowdoIupdatemultipleitems?"},"Message":{"S":"IwanttoupdatemultipleitemsinasingleAPIcall.What'sthebestwaytodothat?"}}}`} 37 for i, v := range s { 38 var d Response 39 um_err := json.Unmarshal([]byte(v), &d) 40 if um_err != nil { 41 t.Errorf("cannot unmarshal to delete:\n" + v + "\n") 42 } 43 json, jerr := json.Marshal(d) 44 if jerr != nil { 45 t.Errorf("cannot marshal\n") 46 } 47 if len(s[i]) != len(string(json)) { 48 e := fmt.Sprintf("\n%s\n%s\nshould be same",s[i],string(json)) 49 t.Errorf(e) 50 } 51 _ = fmt.Sprintf("IN:%v, OUT:%v\n", v, string(json)) 52 } 53 }