github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoints/create_table/create_table_test.go (about) 1 package create_table 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 func TestNil(t *testing.T) { 10 c := NewCreateTable() 11 _,_,err := c.EndpointReqWithConf(nil) 12 if err == nil { 13 t.Errorf("nil conf should result in error") 14 } 15 } 16 17 func TestRequestMarshal(t *testing.T) { 18 s := []string{`{"AttributeDefinitions":[{"AttributeName":"ForumName","AttributeType":"S"},{"AttributeName":"Subject","AttributeType":"S"},{"AttributeName":"LastPostDateTime","AttributeType":"S"}],"TableName":"Thread","KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"Subject","KeyType":"RANGE"}],"LocalSecondaryIndexes":[{"IndexName":"LastPostIndex","KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"LastPostDateTime","KeyType":"RANGE"}],"Projection":{"ProjectionType":"KEYS_ONLY"}}],"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}`, `{"AttributeDefinitions":[{"AttributeName":"ForumName","AttributeType":"S"},{"AttributeName":"Subject","AttributeType":"S"},{"AttributeName":"LastPostDateTime","AttributeType":"S"}],"TableName":"Thread","KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"Subject","KeyType":"RANGE"}],"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}`} 19 for i, v := range s { 20 var c CreateTable 21 um_err := json.Unmarshal([]byte(v), &c) 22 if um_err != nil { 23 t.Errorf("cannot unmarshal\n") 24 } 25 json, jerr := json.Marshal(c) 26 if jerr != nil { 27 t.Errorf("cannot marshal\n") 28 } 29 if len(s[i]) != len(string(json)) { 30 e := fmt.Sprintf("\n%s\n%s\nshould be same",s[i],string(json)) 31 t.Errorf(e) 32 } 33 } 34 } 35 36 func TestResponseMarshal(t *testing.T) { 37 s := []string{`{"TableDescription":{"AttributeDefinitions":[{"AttributeName":"ForumName","AttributeType":"S"},{"AttributeName":"LastPostDateTime","AttributeType":"S"},{"AttributeName":"Subject","AttributeType":"S"}],"CreationDateTime":1.36372808007E9,"ItemCount":0,"KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"Subject","KeyType":"RANGE"}],"LocalSecondaryIndexes":[{"IndexName":"LastPostIndex","IndexSizeBytes":0,"ItemCount":0,"KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"LastPostDateTime","KeyType":"RANGE"}],"Projection":{"ProjectionType":"KEYS_ONLY"}}],"ProvisionedThroughput":{"NumberOfDecreasesToday":0,"ReadCapacityUnits":5,"WriteCapacityUnits":5},"TableName":"Thread","TableSizeBytes":0,"TableStatus":"CREATING"}}`} 38 for _, v := range s { 39 var c Response 40 um_err := json.Unmarshal([]byte(v), &c) 41 if um_err != nil { 42 t.Errorf("cannot unmarshal\n") 43 } 44 _, jerr := json.Marshal(c) 45 if jerr != nil { 46 t.Errorf("cannot marshal\n") 47 } 48 } 49 }