github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/types/expected/expected_test.go (about) 1 package expected 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 // Roundtrip some examples 10 func TestExpectedMarshal(t *testing.T) { 11 s := []string{ 12 `{"MyConstraint1":{"AttributeValueList":[{"S":"a string"}],"ComparisonOperator":"BEGINS_WITH","Value":{"N":"4"},"Exists":true}}`, 13 `{"MyConstraint2":{"AttributeValueList":[{"S":"a string"}],"ComparisonOperator":"BEGINS_WITH","Value":{"N":"4"},"Exists":false}}`, 14 } 15 for i, v := range s { 16 var a Expected 17 um_err := json.Unmarshal([]byte(v), &a) 18 if um_err != nil { 19 t.Errorf("cannot unmarshal\n") 20 } 21 json, jerr := json.Marshal(a) 22 if jerr != nil { 23 t.Errorf("cannot marshal\n") 24 } 25 if len(s[i]) != len(string(json)) { 26 e := fmt.Sprintf("\n%s\n%s\nshould be same",s[i],string(json)) 27 t.Errorf(e) 28 return 29 } 30 } 31 }