github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoints/scan/scan_test.go (about) 1 package scan 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 func TestNil(t *testing.T) { 10 s := NewScan() 11 _,_,err := s.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{`{"TableName":"Reply","ReturnConsumedCapacity":"TOTAL"}`, `{"TableName":"Reply","ScanFilter":{"PostedBy":{"AttributeValueList":[{"S":"joe@example.com"}],"ComparisonOperator":"EQ"}},"ReturnConsumedCapacity":"TOTAL"}`} 19 for _, v := range s { 20 var q Scan 21 um_err := json.Unmarshal([]byte(v), &q) 22 if um_err != nil { 23 e := fmt.Sprintf("unmarshal Query: %v", um_err) 24 t.Errorf(e) 25 } 26 _, jerr := json.Marshal(q) 27 if jerr != nil { 28 t.Errorf("cannot marshal %v\n", jerr) 29 } 30 } 31 } 32 33 func TestResponseUnmarshal(t *testing.T) { 34 s := []string{`{"ConsumedCapacity":{"CapacityUnits":0.5,"TableName":"Reply"},"Count":4,"Items":[{"PostedBy":{"S":"joe@example.com"},"ReplyDateTime":{"S":"20130320115336"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"HaveyoulookedattheBatchWriteItemAPI?"}},{"PostedBy":{"S":"fred@example.com"},"ReplyDateTime":{"S":"20130320115342"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"No,Ididn'tknowaboutthat.WherecanIfindmoreinformation?"}},{"PostedBy":{"S":"joe@example.com"},"ReplyDateTime":{"S":"20130320115347"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"BatchWriteItemisdocumentedintheAmazonDynamoDBAPIReference."}},{"PostedBy":{"S":"fred@example.com"},"ReplyDateTime":{"S":"20130320115352"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"OK,I'lltakealookatthat.Thanks!"}}],"ScannedCount":4}`, `{"ConsumedCapacity":{"CapacityUnits":0.5,"TableName":"Reply"},"Count":2,"Items":[{"PostedBy":{"S":"joe@example.com"},"ReplyDateTime":{"S":"20130320115336"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"HaveyoulookedattheBatchWriteItemAPI?"}},{"PostedBy":{"S":"joe@example.com"},"ReplyDateTime":{"S":"20130320115347"},"Id":{"S":"AmazonDynamoDB#HowdoIupdatemultipleitems?"},"Message":{"S":"BatchWriteItemisdocumentedintheAmazonDynamoDBAPIReference."}}],"ScannedCount":4}`} 35 for _, v := range s { 36 var q Response 37 um_err := json.Unmarshal([]byte(v), &q) 38 if um_err != nil { 39 e := fmt.Sprintf("unmarshal Response: %v", um_err) 40 t.Errorf(e) 41 } 42 _, jerr := json.Marshal(q) 43 if jerr != nil { 44 t.Errorf("cannot marshal\n") 45 } 46 } 47 }