github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/types/localsecondaryindex/localsecondaryindex_test.go (about) 1 package localsecondaryindex 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 func TestLocalSecondaryIndexMarshal(t *testing.T) { 10 s := []string{ 11 `{"IndexName":"LastPostIndex","KeySchema":[{"AttributeName":"ForumName","KeyType":"HASH"},{"AttributeName":"LastPostDateTime","KeyType":"RANGE"}],"Projection":{"ProjectionType":"KEYS_ONLY"}}`, 12 } 13 for i, v := range s { 14 var a LocalSecondaryIndex 15 um_err := json.Unmarshal([]byte(v), &a) 16 if um_err != nil { 17 t.Errorf("cannot unmarshal\n") 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 }