github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/types/globalsecondaryindex/globalsecondaryindex_test.go (about) 1 package globalsecondaryindex 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 // Roundtrip some examples 10 func TestGlobalSecondaryIndexMarshal(t *testing.T) { 11 s := []string{`{"IndexName":"LastPostIndex","KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"LastPostDateTime","KeyType":"RANGE"}],"Projection":{"NonKeyAttributes":null,"ProjectionType":"KEYS_ONLY"},"ProvisionedThroughput":{"ReadCapacityUnits":200,"WriteCapacityUnits":200}}`} 12 for i, v := range s { 13 var a GlobalSecondaryIndex 14 um_err := json.Unmarshal([]byte(v), &a) 15 if um_err != nil { 16 t.Errorf("cannot unmarshal\n") 17 } 18 19 json, jerr := json.Marshal(a) 20 if jerr != nil { 21 t.Errorf("cannot marshal\n") 22 } 23 if len(s[i]) != len(string(json)) { 24 e := fmt.Sprintf("\n%s\n%s\nshould be same",s[i],string(json)) 25 t.Errorf(e) 26 } 27 } 28 }